Closed taimoorgit closed 4 years ago
My apologies. The issue here is useEffect
. What I've done instead in my useEffect
call is to add stripe
into a dependency array, so when stripe
is not null my app will go to Checkout. Exact change:
useEffect(() => {
//apiGetStripePlan();
if (stripe) {
apiGetStripePlan();
}
}, [stripe]);
What should happen: my SPA loads, the Stripe promise runs asynchronously and then I can do things with
useStripe
, for example redirecting to a checkout.My code (I've tried wrapping only UpgradePage with Elements, no difference):
UpgradePage, see apiStripeCheckout:
The problem is that
stripe
in UpgradePage is always null. Even after trying to wait 3 seconds before using it, it is still null, and so I can't redirect my customer to the checkout page that the server gives.After checking the Chrome logs here's what I see:
The API key is loaded just fine. And I've checked my test logs in the Stripe dashboard and I don't see anything unusual. Why is the
loadStripe
promise failing?