8000 Fix: Stripe not working on @formspree/react by bhongy · Pull Request #71 · formspree/formspree-js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: Stripe not working on @formspree/react #71

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 8000 to your account

Merged
merged 2 commits into from
Mar 7, 2025

Conversation

bhongy
Copy link
Contributor
@bhongy bhongy commented Mar 6, 2025

Root cause: stripe?.elements().getElement(CardElement) always return null since stripe.elements() creates a new instance of Elements; resulted in createPaymentMethod was always undefined.

This issue arose because React hooks like useElements cannot be called conditionally. Calling useElements unconditionally will cause errors for users who don't use Stripe.

This PR wraps useElements call in a conditionally rendered component StripeProvider to pass the correct elements instance down via context, so we can get cardElement from it.

Copy link
changeset-bot bot commented Mar 6, 2025

🦋 Changeset detected

Latest commit: fe723c8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@formspree/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
vercel bot commented Mar 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
formspree-react-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 6, 2025 1:38am

@bhongy bhongy requested a review from colevscode March 6, 2025 01:42
@bhongy bhongy merged commit 40a0eae into main Mar 7, 2025
4 checks passed
@bhongy bhongy deleted the fix/stripe-not-working-on-formspree-react branch March 7, 2025 23:17
bhongy added a commit that referenced this pull request Mar 8, 2025
bhongy added a commit that referenced this pull request Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0