Skip to content

Commit 0a537ea

Browse files
committed
feat: Enable using SeamQueryProvider inside existing QueryClientContext
1 parent 0a02e72 commit 0a537ea

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/lib/seam/SeamQueryProvider.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import type {
33
SeamHttpEndpoints,
44
SeamHttpOptionsWithClientSessionToken,
55
} from '@seamapi/http/connect'
6-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
6+
import {
7+
QueryClient,
8+
QueryClientContext,
9+
QueryClientProvider,
10+
} from '@tanstack/react-query'
711
import {
812
createContext,
913
type PropsWithChildren,
@@ -88,9 +92,22 @@ export function SeamQueryProvider({
8892
}
8993

9094
const { Provider } = seamContext
95+
const queryClientFromContext = useContext(QueryClientContext)
96+
97+
if (
98+
queryClientFromContext != null &&
99+
queryClient != null &&
100+
queryClientFromContext !== queryClient
101+
) {
102+
throw new Error(
103+
'The QueryClient passed into SeamQueryProvider is different from the one in the existing QueryClientContext. Omit the queryClient prop from SeamProvider or SeamQueryProvider to use the existing QueryClient provided by the QueryClientProvider.'
104+
)
105+
}
91106

92107
return (
93-
<QueryClientProvider client={queryClient ?? defaultQueryClient}>
108+
<QueryClientProvider
109+
client={queryClientFromContext ?? queryClient ?? defaultQueryClient}
110+
>
94111
<Provider value={value}>
95112
<Session onSessionUpdate={onSessionUpdate}>{children}</Session>
96113
</Provider>

0 commit comments

Comments
 (0)