Stripe has react-stripe-elements, which provides injectStripe
HOC. We're in 2019 and HOCs are not cool anymore. Stripe doesn't appear to be in a hurry, i assume it's because they want to support older versions of React, so are looking at lowest common denominator solutions only.
I'm looking for a way to get stripe
via a hook (instead of a prop provided by injectStripe
).
Usage would look like this
const stripe = useStripe()
so that later I can use stripe.handleCardSetup
and other API methods
import { CardElement } from 'react-stripe-elements'
const CardForm = ({secret}) => {
const stripe = useStripe()
const handleSubmit = async () => {
const { setupIntent, error } = await stripe.handleCardSetup(secret)
// ...
}
return (
<>
<CardElement />
<button onClick={handleSubmit} />
</>
)
}
how would you define useStripe
hook from existing APIs and components?
stripe
should be the same as what you'd get if you used injectStripe
hook
Related issue on GH: API Review: Hooks & Beyond