Skip to content

Commit 163339f

Browse files
authored
feat: throw error when QueryClientProvider has not been used to set a query client (#1309)
Also updated docs
1 parent 70647f9 commit 163339f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ This has some benefits:
2222

2323
Use the `QueryClientProvider` component to connect a `QueryClient` to your application:
2424

25+
**NOTE** There is no longer a default query cache, you must connect your application to a query provider manually
26+
2527
```js
2628
import { QueryClient, QueryClientProvider } from 'react-query'
2729

src/react/QueryClientProvider.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ const QueryClientContext = React.createContext<QueryClient | undefined>(
66
undefined
77
)
88

9-
export const useQueryClient = () => React.useContext(QueryClientContext)!
9+
export const useQueryClient = () => {
10+
const queryClient = React.useContext(QueryClientContext)
11+
if (!queryClient) {
12+
throw new Error('No QueryClient set, use QueryClientProvider to set one')
13+
}
14+
return queryClient
15+
}
1016

1117
export interface QueryClientProviderProps {
1218
client: QueryClient

0 commit comments

Comments
 (0)