You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -892,7 +892,7 @@ function Todo({ todoId }) {
892
892
}
893
893
```
894
894
895
-
Most of the time, this pattern works well, but if the source query you're using to look up the initial data from is old, you may not want to use the data at all and just fetch from the server. To make this decision easier, you can use the `queryCache.getQuery` method instead to get more information about the source query, including an `updatedAt` timestamp you can use to decide if the query is "fresh" enough for your needs:
895
+
Most of the time, this pattern works well, but if the source query you're using to look up the initial data from is old, you may not want to use the data at all and just fetch from the server. To make this decision easier, you can use the `queryCache.getQuery` method instead to get more information about the source query, including a `query.state.updatedAt` timestamp you can use to decide if the query is "fresh" enough for your needs:
896
896
897
897
```js
898
898
functionTodo({ todoId }) {
@@ -902,7 +902,7 @@ function Todo({ todoId }) {
902
902
constquery=queryCache.getQuery('todos')
903
903
904
904
// If the query exists and has data that is no older than 10 seconds...
905
-
if (query &&Date.now() -query.updatedAt<=10*1000) {
905
+
if (query &&Date.now() -query.state.updatedAt<=10*1000) {
906
906
// return the individual todo
907
907
returnquery.state.data.find(d=>d.id=== todoId)
908
908
}
@@ -2435,7 +2435,7 @@ This function does not return anything
2435
2435
2436
2436
`getQuery` is a slightly more advanced synchronous function that can be used to get an existing query object from the cache. This object not only contains **all** the state for the query, but all of the instances, and underlying guts of the query as well. If the query does not exist, `undefined` will be returned.
2437
2437
2438
-
> Note: This is not typically needed for most applications, but can come in handy when needing more information about a query in rare scenarios (eg. Looking at the query.updatedAt timestamp to decide whether a query is fresh enough to be used as an initial value)
2438
+
> Note: This is not typically needed for most applications, but can come in handy when needing more information about a query in rare scenarios (eg. Looking at the query.state.updatedAt timestamp to decide whether a query is fresh enough to be used as an initial value)
2439
2439
2440
2440
```js
2441
2441
import { queryCache } from 'react-query'
@@ -2531,7 +2531,7 @@ queryCache.clear()
2531
2531
The `useQueryCache` hook returns the current queryCache instance.
2532
2532
2533
2533
```js
2534
-
import { useQueryCache } from'react-query';
2534
+
import { useQueryCache } from'react-query'
2535
2535
2536
2536
constqueryCache=useQueryCache()
2537
2537
```
@@ -2603,7 +2603,7 @@ function App() {
2603
2603
`ReactQueryCacheProvider` is an optional provider component for explicitly setting the query cache used by React Query. This is useful for creating component-level caches that are not completely global, as well as making truly isolated unit tests.
0 commit comments