-
Notifications
You must be signed in to change notification settings - Fork 121
useCreatePayLaterOneTimePaymentSession #697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/react-paypal-js-v6
Are you sure you want to change the base?
useCreatePayLaterOneTimePaymentSession #697
Conversation
|
return () => { | ||
sessionRef.current?.destroy(); | ||
sessionRef.current = null; | ||
updateSession(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unclear to me if we need to update the session to null
here.
In the case that the component is unmounted and this clean up runs, then we're updating state within an unmounted component and will trigger a React warning. I read in this blog post that the warning was removed in React 18, but react-paypal-js
is on React 17. Found the actual React Working Group post on it here.
In the case that one of the dependencies has updated and the useEffect is going to rerun, I believe that the previous session will be replaced with the new session before the button re-renders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed on slack here to remove this, but I wanted to keep the comment for posterity's sake
// TODO what if sdk instance is not available? Error? | ||
throw new Error("no sdk instance available"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question about this. I think there are a few reasons that sdkInstance
would be null, like if the hook is being used outside of the Provider for example. I wonder if discussing the error handling strategy overall is a good idea.
No description provided.