You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With react-paypal-js ("@paypal/react-paypal-js": "^8.7.0"), the event handlers seem to create a closure and hold old state - its not clear from the docs on how to avoid this, or update.
Click the button a few times, state updates, but when any of the event handlers of PaypalButton are called, it's the stale state.
Seems you are creating a closure of the event handler functions.
This is a problem because people
go to my checkout, enter their info (which updates cart state)
click Paypal as a payment option - this renders the PaypalButtons component
Then they go back to their checkout and change things like coupon, name or email address.
They click the paypal button
So the state is stale back to when the button was initially rendered.
Am I supposed to force a re-render of the button every time my state changes?
I'd consider this a bug as I'd expect the onClick to just use the state, but if it's not a bug, it needs documentation as it doesn't behave as React event handlers do.
The text was updated successfully, but these errors were encountered:
I'm using nextjs 14.* and have exactly the same problem. It seems that the SDK is not made for SSR because by default every next component is rendered on the server and then hydrated therefore the onFunctions dont get the current state.
The button component needs a 'use client' tag for use in next or a client-only solution.
Do you have the animation problem with the dispatch too, the forceRerender with the animation is not a nice solution.
With react-paypal-js (
"@paypal/react-paypal-js": "^8.7.0"
), the event handlers seem to create a closure and hold old state - its not clear from the docs on how to avoid this, or update.An example:
Click the button a few times, state updates, but when any of the event handlers of PaypalButton are called, it's the stale state.
Seems you are creating a closure of the event handler functions.
This is a problem because people
So the state is stale back to when the button was initially rendered.
Am I supposed to force a re-render of the button every time my state changes?
I'd consider this a bug as I'd expect the onClick to just use the state, but if it's not a bug, it needs documentation as it doesn't behave as React event handlers do.
The text was updated successfully, but these errors were encountered: