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
* docs: useQuery to object syntax
* docs: invalidateQueries to object syntax
* docs: useMutation to object syntax
* docs: infinite query and other references to object syntax
Copy file name to clipboardExpand all lines: docs/comparison.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,7 +69,7 @@ Feature/Capability Key:
69
69
70
70
> **<sup>3</sup> Partial query matching** - Because React Query uses deterministic query key serialization, this allows you to manipulate variable groups of queries without having to know each individual query-key that you want to match, eg. you can refetch every query that starts with `todos` in its key, regardless of variables, or you can target specific queries with (or without) variables or nested properties, and even use a filter function to only match queries that pass your specific conditions.
71
71
72
-
> **<sup>4</sup> Pre-usage Query Configuration** - This is simply a fancy name for being able to configure how queries and mutations will behave before they are used. For instance, a query can be fully configured with defaults beforehand and when the time comes to use it, only `useQuery(key)` is necessary, instead of being required to pass the fetcher and/or options with every usage. SWR does have a partial form of this feature by allowing you to pre-configure a default fetcher, but only as a global fetcher, not on a per-query basis and definitely not for mutations.
72
+
> **<sup>4</sup> Pre-usage Query Configuration** - This is simply a fancy name for being able to configure how queries and mutations will behave before they are used. For instance, a query can be fully configured with defaults beforehand and when the time comes to use it, only `useQuery({ queryKey })` is necessary, instead of being required to pass the fetcher and/or options with every usage. SWR does have a partial form of this feature by allowing you to pre-configure a default fetcher, but only as a global fetcher, not on a per-query basis and definitely not for mutations.
73
73
74
74
> **<sup>5</sup> Automatic Refetch after Mutation** - For truly automatic refetching to happen after a mutation occurs, a schema is necessary (like the one graphQL provides) along with heuristics that help the library know how to identify individual entities and entities types in that schema.
Copy file name to clipboardExpand all lines: docs/guides/caching.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,18 +16,18 @@ This caching example illustrates the story and lifecycle of:
16
16
17
17
Let's assume we are using the default `cacheTime` of **5 minutes** and the default `staleTime` of `0`.
18
18
19
-
- A new instance of `useQuery(['todos'], fetchTodos)` mounts.
19
+
- A new instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` mounts.
20
20
- Since no other queries have been made with the `['todos']` query key, this query will show a hard loading state and make a network request to fetch the data.
21
21
- When the network request has completed, the returned data will be cached under the `['todos']` key.
22
22
- The hook will mark the data as stale after the configured `staleTime` (defaults to `0`, or immediately).
23
-
- A second instance of `useQuery(['todos'], fetchTodos)` mounts elsewhere.
23
+
- A second instance of `useQuery({ queyKey: ['todos'], queryFn: fetchTodos })` mounts elsewhere.
24
24
- Since the cache already has data for the `['todos']` key from the first query, that data is immediately returned from the cache.
25
25
- The new instance triggers a new network request using its query function.
26
26
- Note that regardless of whether both `fetchTodos` query functions are identical or not, both queries' [`status`](../reference/useQuery) are updated (including `isFetching`, `isLoading`, and other related values) because they have the same query key.
27
27
- When the request completes successfully, the cache's data under the `['todos']` key is updated with the new data, and both instances are updated with the new data.
28
-
- Both instances of the `useQuery(['todos'], fetchTodos)` query are unmounted and no longer in use.
28
+
- Both instances of the `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` query are unmounted and no longer in use.
29
29
- Since there are no more active instances of this query, a cache timeout is set using `cacheTime` to delete and garbage collect the query (defaults to **5 minutes**).
30
-
- Before the cache timeout has completed, another instance of `useQuery(['todos'], fetchTodos)` mounts. The query immediately returns the available cached data while the `fetchTodos` function is being run in the background. When it completes successfully, it will populate the cache with fresh data.
31
-
- The final instance of `useQuery(['todos'], fetchTodos)` unmounts.
32
-
- No more instances of `useQuery(['todos'], fetchTodos)` appear within **5 minutes**.
30
+
- Before the cache timeout has completed, another instance of `useQuery({ queryKey: ['todos'], queyFn: fetchTodos })` mounts. The query immediately returns the available cached data while the `fetchTodos` function is being run in the background. When it completes successfully, it will populate the cache with fresh data.
31
+
- The final instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` unmounts.
32
+
- No more instances of `useQuery({ queyKey: ['todos'], queryFn: fetchTodos })` appear within **5 minutes**.
33
33
- The cached data under the `['todos']` key is deleted and garbage collected.
0 commit comments