diff --git a/src/components/CustomCheckout.test.tsx b/src/components/CustomCheckout.test.tsx index d71edc5..7be6dbb 100644 --- a/src/components/CustomCheckout.test.tsx +++ b/src/components/CustomCheckout.test.tsx @@ -3,7 +3,8 @@ import {render, act, waitFor} from '@testing-library/react'; import {renderHook} from '@testing-library/react-hooks'; import {CustomCheckoutProvider, useCustomCheckout} from './CustomCheckout'; -import {Elements, useStripe} from './Elements'; +import {Elements} from './Elements'; +import {useStripe} from './useStripe'; import * as mocks from '../../test/mocks'; describe('CustomCheckoutProvider', () => { diff --git a/src/components/Elements.test.tsx b/src/components/Elements.test.tsx index 5b9016a..3b4a984 100644 --- a/src/components/Elements.test.tsx +++ b/src/components/Elements.test.tsx @@ -8,9 +8,9 @@ import { ElementsConsumer, useCartElement, useCartElementState, - useStripe, } from './Elements'; import * as mocks from '../../test/mocks'; +import {useStripe} from './useStripe'; describe('Elements', () => { let mockStripe: any; diff --git a/src/components/Elements.tsx b/src/components/Elements.tsx index 1a93700..8bb919f 100644 --- a/src/components/Elements.tsx +++ b/src/components/Elements.tsx @@ -17,7 +17,6 @@ import { } from '../utils/extractAllowedOptionsUpdates'; import {parseStripeProp} from '../utils/parseStripeProp'; import {registerWithStripeJs} from '../utils/registerWithStripeJs'; -import {useElementsOrCustomCheckoutSdkContextWithUseCase} from './CustomCheckout'; export interface ElementsContextValue { elements: stripeJs.StripeElements | null; @@ -240,16 +239,6 @@ export const useElements = (): stripeJs.StripeElements | null => { return elements; }; -/** - * @docs https://stripe.com/docs/stripe-js/react#usestripe-hook - */ -export const useStripe = (): stripeJs.Stripe | null => { - const {stripe} = useElementsOrCustomCheckoutSdkContextWithUseCase( - 'calls useStripe()' - ); - return stripe; -}; - /** * @docs https://stripe.com/docs/payments/checkout/cart-element */ diff --git a/src/components/useStripe.tsx b/src/components/useStripe.tsx new file mode 100644 index 0000000..6cf3566 --- /dev/null +++ b/src/components/useStripe.tsx @@ -0,0 +1,12 @@ +import * as stripeJs from '@stripe/stripe-js'; +import {useElementsOrCustomCheckoutSdkContextWithUseCase} from './CustomCheckout'; + +/** + * @docs https://stripe.com/docs/stripe-js/react#usestripe-hook + */ +export const useStripe = (): stripeJs.Stripe | null => { + const {stripe} = useElementsOrCustomCheckoutSdkContextWithUseCase( + 'calls useStripe()' + ); + return stripe; +}; diff --git a/src/index.ts b/src/index.ts index a9e22fb..cedd915 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,7 +26,6 @@ import {isServer} from './utils/isServer'; export * from './types'; export { - useStripe, useElements, useCartElement, useCartElementState, @@ -40,6 +39,7 @@ export { } from './components/CustomCheckout'; export {EmbeddedCheckout} from './components/EmbeddedCheckout'; export {EmbeddedCheckoutProvider} from './components/EmbeddedCheckoutProvider'; +export {useStripe} from './components/useStripe'; /** * Requires beta access: