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
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ Tools for managing async data and client stores/caches are plentiful these days,
53
53
- Force normalized or object/id-based caching strategies on your data
54
54
- Do not automatically manage stale-ness or caching
55
55
- Do not offer robust API's around mutation events, invalidation or query management
56
-
- Are built for highly-opinionated systems like Redux, GraphQL, [insert proprietary tools] etc.
56
+
- Are built for highly-opinionated systems like Redux, GraphQL, [insert proprietary tools], etc.
57
57
58
58
## The Solution
59
59
@@ -299,7 +299,7 @@ function Todos() {
299
299
300
300
### Query Keys
301
301
302
-
Since React Query uses a query's **unique key** for essentially everything, it's important to tailor them so that will change with your query requirements. In other libraries like Zeit's SWR, you'll see the use of URL's and GraphQL query template strings to achieve this, but we believe at scale, this becomes prone to typos and errors. To relieve this issue, you can pass a **tuple key** with a `string` and `object` of variables to deterministically get the the same key.
302
+
Since React Query uses a query's **unique key** for essentially everything, it's important to tailor them so that they will change with your query requirements. In other libraries like Zeit's SWR, you'll see the use of URL's and GraphQL query template strings to achieve this, but we believe at scale, this becomes prone to typos and errors. To relieve this issue, you can pass a **tuple key** with a `string` and `object` of variables to deterministically get the same key.
303
303
304
304
> Pro Tip: Variables passed in the key are automatically passed to your query function!
To use external props, state, or variables in a query function, pass them as a variables in your query key! They will be passed through to your query function as the first parameter.
316
+
To use external props, state, or variables in a query function, pass them as a variable in your query key! They will be passed through to your query function as the first parameter.
317
317
318
318
```js
319
319
functionTodos({ status }) {
@@ -409,7 +409,7 @@ Let's assume we are using the default `cacheTime` of **5 minutes** and the defau
409
409
- A second instance of `useQuery('todos', fetchTodos)` mounts elsewhere.
410
410
- Because this exact data exist in the cache from the first instance of this query, that data is immediately returned from the cache.
411
411
- Since the query is stale, it is refetched in the background automatically.
412
-
- Both instances of the `useQuery('todos', fetchTodos)` query are unmount and no longer in use.
412
+
- Both instances of the `useQuery('todos', fetchTodos)` query are unmounted and no longer in use.
413
413
- Since there are no more active instances to this query, a cache timeout is set using `cacheTime` to delete and garbage collect the query (defaults to **5 minutes**).
414
414
- No more instances of `useQuery('todos', fetchTodos)` appear within **5 minutes**.
415
415
- This query and its data is deleted and garbage collected.
The query's state will still reflect that it is stale and has not been fetched yet, and once mounted, will continue as normal and request a fresh copy of the query result.
664
+
The query's state will still reflect that it is stale and has not been fetched yet, and once mounted, it will continue as normal and request a fresh copy of the query result.
**Most importantly**, when manually setting a query response, it naturally becomes out-of-sync with it's original source. To ease this issue, `setQueryData` automatically triggers a background refresh of the query after it's called to ensure it eventually synchronizes with the original source.
947
+
**Most importantly**, when manually setting a query response, it naturally becomes out-of-sync with its original source. To ease this issue, `setQueryData` automatically triggers a background refresh of the query after it's called to ensure it eventually synchronizes with the original source.
948
948
949
949
Should you choose that you do _not_ want to refetch the query automatically, you can set the `shouldRefetch` option to `false`:
950
950
@@ -1015,7 +1015,7 @@ function App() {
1015
1015
1016
1016
### Custom Window Focus Event
1017
1017
1018
-
In rare circumstances, you may want manage your own window focus events that trigger React Query to revalidate. To do this, React Query provides a `setFocusHandler` function that supplies you the callback that should be fired when the window is focused and allows you to set up your own events. When calling `setFocusHandler`, the previously set handler is removed (which in most cases will be the defalt handler) and your new handler is used instead. For example, this is the default handler:
1018
+
In rare circumstances, you may want to manage your own window focus events that trigger React Query to revalidate. To do this, React Query provides a `setFocusHandler` function that supplies you the callback that should be fired when the window is focused and allows you to set up your own events. When calling `setFocusHandler`, the previously set handler is removed (which in most cases will be the default handler) and your new handler is used instead. For example, this is the default handler:
A greate use-case for replacing the focus handler is that of iframe events. Iframes present problems with detecting window focus by both double-firing events and also firing false-positive events when focusing or using iframes within your app. If you experience this, you should use an event handler that ignores these events as much as possible. I recommend [this one](https://gist.github.com/tannerlinsley/1d3a2122332107fcd8c9cc379be10d88)! It can be set up in the following way:
1038
+
A great use-case for replacing the focus handler is that of iframe events. Iframes present problems with detecting window focus by both double-firing events and also firing false-positive events when focusing or using iframes within your app. If you experience this, you should use an event handler that ignores these events as much as possible. I recommend [this one](https://gist.github.com/tannerlinsley/1d3a2122332107fcd8c9cc379be10d88)! It can be set up in the following way:
- If `shouldRefetch` is `true`, a promise is returned that will either resolve when the query refetch is complete or will reject if the refetch fails (after its respective retry configurations is done).
1442
+
- If `shouldRefetch` is `true`, a promise is returned that will either resolve when the query refetch is complete or will reject if the refetch fails (after its respective retry configurations are done).
0 commit comments