Skip to content

Commit 584932e

Browse files
committed
docs: fix to query.state.updatedAt
Fixes #497
1 parent 80e82da commit 584932e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ function Todo({ todoId }) {
892892
}
893893
```
894894
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:
896896
897897
```js
898898
function Todo({ todoId }) {
@@ -902,7 +902,7 @@ function Todo({ todoId }) {
902902
const query = queryCache.getQuery('todos')
903903

904904
// 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) {
906906
// return the individual todo
907907
return query.state.data.find(d => d.id === todoId)
908908
}
@@ -2435,7 +2435,7 @@ This function does not return anything
24352435

24362436
`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.
24372437

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)
24392439

24402440
```js
24412441
import { queryCache } from 'react-query'
@@ -2531,7 +2531,7 @@ queryCache.clear()
25312531
The `useQueryCache` hook returns the current queryCache instance.
25322532
25332533
```js
2534-
import { useQueryCache } from 'react-query';
2534+
import { useQueryCache } from 'react-query'
25352535

25362536
const queryCache = useQueryCache()
25372537
```
@@ -2603,7 +2603,7 @@ function App() {
26032603
`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.
26042604
26052605
```js
2606-
import { ReactQueryCacheProvider, makeQueryCache } from 'react-query';
2606+
import { ReactQueryCacheProvider, makeQueryCache } from 'react-query'
26072607

26082608
const queryCache = makeQueryCache()
26092609

@@ -2617,6 +2617,7 @@ function App() {
26172617
```
26182618
26192619
### Options
2620+
26202621
- `queryCache: Object`
26212622
- In instance of queryCache, you can use the `makeQueryCache` factory to create this.
26222623
- If not provided, a new cache will be generated.

0 commit comments

Comments
 (0)