skip to Main Content

I want to use the latest stripe sdk @stripe/stripe-react-native in older react native project based in class component ?
The doc stripe use the hooks,there is no example that used class component,So need help and thanks.

2

Answers


  1. Chosen as BEST ANSWER

    Yes,I found the solution such as wrap code with stripe provider or use initstripe both direcly from module thanks for your reply .


  2. All of the stripe functions can be imported directly from @stripe/stripe-react-native so that you can use them both with class and functional components.
    However, you are also able to access them via dedicated hooks.
    For instance you can use useConfirmPayment hook which apart from confirmPayment method provides also loading state so you don’t need to handle it manually.
    Moreover, there is also the main useStripe hook which provides all of the stripe methods.
    examples:

    1.

    import { useConfirmPayment } from '@stripe/stripe-react-native';
    
    const { confirmPayment, loading } = useConfirmPayment();
    
    // await confirmPayment(...)
    
    import { useStripe } from '@stripe/stripe-react-native';
    
    const { confirmPayment } = useStripe();
    
    // await confirmPayment(...)
    
    import { confirmPayment } from '@stripe/stripe-react-native';
    
    // await confirmPayment(...)
    

    Source: https://github.com/stripe/stripe-react-native/blob/master/docs/tipsi-stripe-migration-guide.md#class-vs-functional-components

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search