Skip to content

Commit

Permalink
Remove cyclic dependency (#474)
Browse files Browse the repository at this point in the history
* Remove cyclic dependency

* fix tests
  • Loading branch information
cbala-stripe authored Feb 26, 2024
1 parent f761e26 commit a1e5127
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/components/CustomCheckout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Elements.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 0 additions & 11 deletions src/components/Elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
12 changes: 12 additions & 0 deletions src/components/useStripe.tsx
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {isServer} from './utils/isServer';
export * from './types';

export {
useStripe,
useElements,
useCartElement,
useCartElementState,
Expand All @@ -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:
Expand Down

0 comments on commit a1e5127

Please sign in to comment.