Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
feat(shared): Remove SWR#7455
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
Uh oh!
There was an error while loading. Please reload this page.
feat(shared): Remove SWR #7455
Changes from all commits
eb0bae16ee75beb55dc0eca516906e885b61ab5baef3337106baf6ce88ac0c5acdecff1a351ae6b2cae19fa9cdaFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/shared': major | ||
| --- | ||
| Remove SWR hooks and env-based switchovers in favor of the React Query implementations; promote @tanstack/query-core to a runtime dependency. |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,76 @@ | ||
| export type { UseInitializePaymentMethodResult } from 'virtual:data-hooks/useInitializePaymentMethod'; | ||
| export { __internal_useInitializePaymentMethod } from 'virtual:data-hooks/useInitializePaymentMethod'; | ||
| import { useCallback, useMemo } from 'react'; | ||
| import type { BillingInitializedPaymentMethodResource, ForPayerType } from '../../types'; | ||
| import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data'; | ||
| import { useClerkQueryClient } from '../clerk-rq/use-clerk-query-client'; | ||
| import { useClerkQuery } from '../clerk-rq/useQuery'; | ||
| import { useOrganizationContext, useUserContext } from '../contexts'; | ||
| import { useBillingHookEnabled } from '../hooks/useBillingHookEnabled'; | ||
| type InitializePaymentMethodOptions = { | ||
| for?: ForPayerType; | ||
| }; | ||
| export type UseInitializePaymentMethodResult = { | ||
| initializedPaymentMethod: BillingInitializedPaymentMethodResource | undefined; | ||
| initializePaymentMethod: () => Promise<BillingInitializedPaymentMethodResource | undefined>; | ||
| }; | ||
| /** | ||
| * @internal | ||
| */ | ||
| function useInitializePaymentMethod(options?: InitializePaymentMethodOptions): UseInitializePaymentMethodResult { | ||
| const { for: forType } = options ?? {}; | ||
| const { organization } = useOrganizationContext(); | ||
| const user = useUserContext(); | ||
| const resource = forType === 'organization' ? organization : user; | ||
| const billingEnabled = useBillingHookEnabled(options); | ||
| const queryKey = useMemo(() => { | ||
| return ['billing-payment-method-initialize', { resourceId: resource?.id }] as const; | ||
| }, [resource?.id]); | ||
| const isEnabled = Boolean(resource?.id) && billingEnabled; | ||
| const query = useClerkQuery({ | ||
| queryKey, | ||
| queryFn: async () => { | ||
| if (!resource) { | ||
| return undefined; | ||
| } | ||
| return resource.initializePaymentMethod({ | ||
| gateway: 'stripe', | ||
| }); | ||
| }, | ||
| enabled: isEnabled, | ||
| staleTime: 1_000 * 60, | ||
| refetchOnWindowFocus: false, | ||
| placeholderData: defineKeepPreviousDataFn(true), | ||
| }); | ||
| const [queryClient] = useClerkQueryClient(); | ||
| const initializePaymentMethod = useCallback(async () => { | ||
| if (!resource) { | ||
| return undefined; | ||
| } | ||
| const result = await resource.initializePaymentMethod({ | ||
| gateway: 'stripe', | ||
| }); | ||
| queryClient.setQueryData(queryKey, result); | ||
| return result; | ||
| }, [queryClient, queryKey, resource]); | ||
| return { | ||
| initializedPaymentMethod: query.data ?? undefined, | ||
| initializePaymentMethod, | ||
| }; | ||
| } | ||
| export { useInitializePaymentMethod as __internal_useInitializePaymentMethod }; |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.