Skip to content

Commit 7bba5a9

Browse files
committed
docs(v4): update context example in v4 migration guide
1 parent 5562cfa commit 7bba5a9

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

docs/src/pages/guides/migrating-to-react-query-4.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ When using the [functional updater form of setQueryData](../reference/QueryClien
357357

358358
### Custom Contexts for Multiple Providers
359359

360-
Custom contexts can now be specified to pair hooks with their matching `Provider`. This is critical when there may be multiple React Query `Provider` instances in the component tree and you need to ensure your hook uses the correct `Provider` instance.
360+
Custom contexts can now be specified to pair hooks with their matching `Provider`. This is critical when there may be multiple React Query `Provider` instances in the component tree, and you need to ensure your hook uses the correct `Provider` instance.
361361

362362
An example:
363363

@@ -366,23 +366,21 @@ An example:
366366
```tsx
367367
// Our first data package: @my-scope/container-data
368368

369-
const context = React.createContext<QueryClient | undefined>();
370-
const queryCache = new QueryCache()
371-
const queryClient = new QueryClient({ queryCache, context })
372-
369+
const context = React.createContext<QueryClient | undefined>(undefined)
370+
const queryClient = new QueryClient()
373371

374372
export const useUser = () => {
375373
return useQuery(USER_KEY, USER_FETCHER, {
376374
context,
377375
})
378376
}
379377

380-
export const ContainerDataProvider: React.FC = ({ children }) => {
378+
export const ContainerDataProvider = ({ children }: { children: React.ReactNode}) => {
381379
return (
382380
<QueryClientProvider client={queryClient} context={context}>
383381
{children}
384382
</QueryClientProvider>
385-
);
383+
)
386384
}
387385

388386
```
@@ -392,9 +390,8 @@ export const ContainerDataProvider: React.FC = ({ children }) => {
392390
```tsx
393391
// Our second data package: @my-scope/my-component-data
394392

395-
const context = React.createContext<QueryClient | undefined>();
396-
const queryCache = new QueryCache()
397-
const queryClient = new QueryClient({ queryCache, context })
393+
const context = React.createContext<QueryClient | undefined>(undefined)
394+
const queryClient = new QueryClient()
398395

399396

400397
export const useItems = () => {
@@ -403,12 +400,12 @@ export const useItems = () => {
403400
})
404401
}
405402

406-
export const MyComponentDataProvider: React.FC = ({ children }) => {
403+
export const MyComponentDataProvider = ({ children }: { children: React.ReactNode}) => {
407404
return (
408405
<QueryClientProvider client={queryClient} context={context}>
409406
{children}
410407
</QueryClientProvider>
411-
);
408+
)
412409
}
413410

414411
```
@@ -436,8 +433,8 @@ import { MyComponentDataProvider, useItems } from "@my-scope/my-component-data";
436433

437434
// Example of hooks provided by the "DataProvider" components above:
438435
const MyComponent = () => {
439-
const user = useUser(); // <-- Uses the context specified in ContainerDataProvider.
440-
const items = useItems(); // <-- Uses the context specified in MyComponentDataProvider
436+
const user = useUser() // <-- Uses the context specified in ContainerDataProvider.
437+
const items = useItems() // <-- Uses the context specified in MyComponentDataProvider
441438
...
442439
}
443440
```

0 commit comments

Comments
 (0)