Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cyclic dependency #474

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading