Skip to content

Commit 627f7b5

Browse files
authored
doc: notes about using context providers with RSC (#408)
1 parent 4a88ab4 commit 627f7b5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/reference/plugins/tanstack-query.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,31 @@ provideHooksContext({
183183
184184
</Tabs>
185185
186+
:::info Notes about Next.js app router
187+
188+
Next.js's app router renders components as React Server Components (RSC) by default. React context providers are not supported in RSC. If you're configuring the context providers in such a setup, please make sure to wrap them inside a client component, or set the containing layout as client component.
189+
190+
```tsx title='providers.tsx'
191+
'use client';
192+
193+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
194+
import { Provider as ZenStackHooksProvider } from "@/hooks/generated";
195+
import type { ReactNode } from 'react';
196+
197+
const queryClient = new QueryClient();
198+
199+
export default function Providers({ children }: { children: ReactNode }) {
200+
return (
201+
<QueryClientProvider client={queryClient}>
202+
<ZenStackHooksProvider value={{ endpoint: '/api/model' }}>
203+
{children}
204+
</ZenStackHooksProvider>
205+
</QueryClientProvider>
206+
);
207+
}
208+
```
209+
:::
210+
186211
### Example
187212
188213
Here's a quick example with a ReactJs blogging app. You can find a fully functional Todo app example [here](https://github.com/zenstackhq/sample-todo-nextjs-tanstack).

0 commit comments

Comments
 (0)