#Pedro Hercules
1 messages · Page 1 of 1 (latest)
Hi there
So you want to wait to render these components and your Elements Provider until you have the client secret. So you want to do something like {clientSecret && ( <Elements options={options} stripe={stripePromise}>
That will ensure the clientSecret is present first
It works, thank you.
👍
Hi again
When i'll try build returns this error: Error: Could not find Elements context; You need to wrap the part of your app that calls useStripe() in an <Elements> provider.
Is the component that useStripe in wrapped in your <Elements> component?
const StripeCheckout = (options: any) => { const stripePromise = loadStripe( process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY || '' ) return ( <Elements stripe={stripePromise} options={options}> <CheckoutForm /> </Elements> ) }
Yep okay and useStripe is within your CheckoutForm component?
yes
In your CheckoutForm component are you waiting to ensure that stripe is initialized?
Like do you have ```useEffect(() => {
if (!stripe) {
return;
}
Hmm well seems fine to me then. I'd add logs to your code to see if stripe is initialized before you are calling stripe.*