stripe / react-stripe-js

React components for Stripe.js and Stripe Elements
https://stripe.com/docs/stripe-js/react
MIT License
1.75k stars 267 forks source link

[BUG]: Multiple Element providers interfere with each other #432

Closed dscafati closed 1 year ago

dscafati commented 1 year ago

What happened?

What I expect to see is the PaymentElement inside of CheckoutScreenVersion2 rendered in the screen based on the configuration from options2

Environment

No response

Reproduction

No response

dscafati commented 1 year ago

Solved by keeping the two Elements mounted and just conditionally showing or hiding their contents

brendanm-stripe commented 1 year ago

It's likely that the switch is leading the new Elements to take over the old ones and inherit some options. Glad you got things working as needed! An alternative you can try is setting distinct key properties on each so React knows they are in fact different components when switching.