#RomanDEV
1 messages · Page 1 of 1 (latest)
hi! let me think about this
The underlying issue is that you're trying to assign a value to your stripePromise prop using your useState hook that doesn't match it's type defs. You need to make it typed:
useState<>(null)
Trying to think what type you need to use 🤔
Maybe it's just useState<Stripe | null>(null)
And: import type { Stripe } from '@stripe/stripe-js'
Ok, this worked for me (just tested):
const [stripePromise, setStripePromise] = React.useState<Promise<Stripe | null>>(null)
React.useEffect(() => {
setStripePromise(loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY))
}, [])
Thanks for your response. In the tutorial we get the publishable Key from the backend. I have tried, what you have tested and null is underlined and not assignable, but the publishable Key is logged. So perhaps it works. I try it. 🙂
The publishableKey issue is separate I think. loadStripe types def expects a string (https://github.com/stripe/stripe-js/blob/a3fc23bc30cc7c43c65980214762288b146a8665/types/index.d.ts#L6-L9), yet at compile time it will be undefined until your backend call resolves
Eh, I don't get any type warnings with your exact code