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
* feat: query key array
remove code that internally ensures that we get an Array, because it is now the expected interface, ensured by TypeScript
* feat: query key array
update tests to the new syntax
* feat: query key array
fix assertions, because there is no array wrapping happening internally anymore. The key you receive from the context is exactly the key you passed in
* feat: query key array
this test doesn't make much sense anymore
* feat: query key array
wrapping in an extra array doesn't yield the same results anymore since v4 because keys need to be an array
* feat: query key array
make docs adhere to new array key syntax
* feat: query key array
migration docs
Copy file name to clipboardExpand all lines: docs/src/pages/guides/caching.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -16,17 +16,17 @@ 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(['todos'], fetchTodos)` mounts.
20
20
- Since no other queries have been made with this query + variable combination, this query will show a hard loading state and make a network request to fetch the data.
21
-
- It will then cache the data using `'todos'` and `fetchTodos` as the unique identifiers for that cache.
21
+
- It will then cache the data using `['todos']` as the unique identifiers for that cache.
22
22
- The hook will mark itself 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(['todos'], fetchTodos)` mounts elsewhere.
24
24
- Because this exact data exists in the cache from the first instance of this query, that data is immediately returned from the cache.
25
25
- A background refetch is triggered for both queries (but only one request), since a new instance appeared on screen.
26
26
- Both instances are updated with the new data if the fetch is successful
27
-
- Both instances of the `useQuery('todos', fetchTodos)` query are unmounted and no longer in use.
27
+
- Both instances of the `useQuery(['todos'], fetchTodos)` query are unmounted and no longer in use.
28
28
- 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**).
29
-
- Before the cache timeout has completed another instance of `useQuery('todos', fetchTodos)` mounts. The query immediately returns the available cached value while the `fetchTodos` function is being run in the background to populate the query with a fresh value.
30
-
- The final instance of `useQuery('todos', fetchTodos)` unmounts.
31
-
- No more instances of `useQuery('todos', fetchTodos)` appear within **5 minutes**.
29
+
- Before the cache timeout has completed another instance of `useQuery(['todos'], fetchTodos)` mounts. The query immediately returns the available cached value while the `fetchTodos` function is being run in the background to populate the query with a fresh value.
30
+
- The final instance of `useQuery(['todos'], fetchTodos)` unmounts.
31
+
- No more instances of `useQuery(['todos'], fetchTodos)` appear within **5 minutes**.
32
32
- This query and its data are deleted and garbage collected.
Bi-directional lists can be implemented by using the `getPreviousPageParam`, `fetchPreviousPage`, `hasPreviousPage` and `isFetchingPreviousPage` properties and functions.
Copy file name to clipboardExpand all lines: docs/src/pages/guides/migrating-to-react-query-4.md
+13
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,19 @@ title: Migrating to React Query 4
5
5
6
6
## Breaking Changes
7
7
8
+
### Query Keys (and Mutation Keys) need to be an Array
9
+
10
+
In v3, Query and Mutation Keys could be a String or an Array. Internally, React Query has always worked with Array Keys only, and we've sometimes exposed this to consumers. For example, in the `queryFn`, you would always get the key as an Array to make working with [Default Query Functions](./default-query-function) easier.
11
+
12
+
However, we have not followed this concept through to all apis. For example, when using the `predicate` function on [Query Filters](./filters) you would get the raw Query Key. This makes it difficult to work with such functions if you use Query Keys that are mixed Arrays and Strings. The same was true when using global callbacks.
13
+
14
+
To streamline all apis, we've decided to make all keys Arrays only:
15
+
16
+
```diff
17
+
- useQuery('todos', fetchTodos)
18
+
+ useQuery(['todos'], fetchTodos)
19
+
```
20
+
8
21
### Separate hydration exports have been removed
9
22
10
23
With version [3.22.0](https://github.com/tannerlinsley/react-query/releases/tag/v3.22.0), hydration utilities moved into the react-query core. With v3, you could still use the old exports from `react-query/hydration`, but these exports have been removed with v4.
0 commit comments