stripe-archive / react-stripe-elements

Moved to stripe/react-stripe-js.
https://github.com/stripe/react-stripe-js
MIT License
3.03k stars 319 forks source link

this.props.stripe.elements is not a function #513

Closed lhtdesignde closed 4 years ago

lhtdesignde commented 4 years ago

Hi, we are just running into an error related to elements. This started happening for us yesterday. We are running the latest version 6.1.1 with react 16.13. We are pulling in stripe (https://js.stripe.com/v3/) in the head.

Screenshot 2020-04-02 at 23 25 45

It seems this.props.stripe is defined but elements() never gets created. Do you maybe have an idea why this error could happen?

christopher-stripe commented 4 years ago

Hi @lhtdesignde, could you provide some information about the calling code here? What does the componentDidMount hook in StripeNewCardForm.js look like? What version of react-stripe-elements are you using?

lhtdesignde commented 4 years ago

We think it was a race condition. We moved the stripe script further up to get initialized earlier. Using the latest version 6.1.1 of react-stripe-elements. componentDidMount just does const elements = this.props.stripe.elements(); where elements() function would not be defined at this point.