Skip to content
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

Not compatible with StrictMode #100

Closed
theKashey opened this issue Jun 9, 2020 · 4 comments
Closed

Not compatible with StrictMode #100

theKashey opened this issue Jun 9, 2020 · 4 comments
Assignees
Labels

Comments

@theKashey
Copy link

Summary

We have discovered that this package is not compatible with StrictMode if sync mode is used.
Async mode is working without any issues.

Other information

I've opened an issue for React, as long as it needs some clarification. All detailed are listed there, and I hope solution will be also found there.

facebook/react#19103

@theKashey
Copy link
Author

In short - you should not use "ref-based" logic. Instead of

 final.current = true; // 👈 this is a problem
      setContext({
        stripe: parsed.stripe,
        elements: parsed.stripe.elements(options),
      });

You can use useReducer based logic or even something as simple as

      setContext(oldState => oldState.stripe ? oldState : {
        stripe: parsed.stripe,
        elements: parsed.stripe.elements(options),
      });

Which would basically setState only once, and would not trigger any re-renders on following invocations.

@christopher-stripe
Copy link
Contributor

Hey @theKashey, thanks for reporting. There's some work in progress that should address this (#93). I'll make sure to follow up here once it is complete.

@stale
Copy link

stale bot commented Mar 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 13, 2021
@stale stale bot closed this as completed Mar 20, 2021
@mxcl
Copy link

mxcl commented May 9, 2021

Is there a safe workaround? I dislike warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants