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
A query filter object supports the following properties:
27
27
28
28
-`exact?: boolean`
29
29
- If you don't want to search queries inclusively by query key, you can pass the `exact: true` option to return only the query with the exact query key you have passed.
30
-
-`active?: boolean`
31
-
- When set to `true` it will match active queries.
32
-
- When set to `false` it will match inactive queries.
33
-
-`inactive?: boolean`
34
-
- When set to `true` it will match inactive queries.
35
-
- When set to `false` it will match active queries.
30
+
-`type?: 'active' | 'inactive' | 'all'`
31
+
- Defaults to `all`
32
+
- When set to `active` it will match active queries.
33
+
- When set to `inactive` it will match inactive queries.
36
34
-`stale?: boolean`
37
35
- When set to `true` it will match stale queries.
38
36
- When set to `false` it will match fresh queries.
> Note: There is no change in behaviour for automatically triggered fetches, e.g. because a query mounts or because of a window focus refetch.
48
+
49
+
### Query Filters
50
+
51
+
A [query filter](../guides/filters) is an object with certain conditions to match a query. Historically, the filter options have mostly been a combination of boolean flags. However, combining those flags can lead to impossible states. Specifically:
52
+
53
+
```
54
+
active?: boolean
55
+
- When set to true it will match active queries.
56
+
- When set to false it will match inactive queries.
57
+
inactive?: boolean
58
+
- When set to true it will match inactive queries.
59
+
- When set to false it will match active queries.
60
+
```
61
+
62
+
Those flags don't work well when used together, because they are mutually exclusive. Setting `false` for both flags could match all queries, judging from the description, or no queries, which doesn't make much sense.
63
+
64
+
With v4, those filters have been combined into a single filter to better show the intent:
65
+
66
+
```diff
67
+
- active?: boolean
68
+
- inactive?: boolean
69
+
+ type?: 'active' | 'inactive' | 'all'
70
+
```
71
+
72
+
The filter defaults to `all`, and you can choose to only match `active` or `inactive` queries.
73
+
74
+
#### refetchActive / refetchInactive
75
+
76
+
[queryClient.invalidateQueries](../reference/QueryClient#queryclientinvalidatequeries) had two additional, similar flags:
77
+
78
+
```
79
+
refetchActive: Boolean
80
+
- Defaults to true
81
+
- When set to false, queries that match the refetch predicate and are actively being rendered via useQuery and friends will NOT be refetched in the background, and only marked as invalid.
82
+
refetchInactive: Boolean
83
+
- Defaults to false
84
+
- When set to true, queries that match the refetch predicate and are not being rendered via useQuery and friends will be both marked as invalid and also refetched in the background
85
+
```
86
+
87
+
For the same reason, those have also been combined:
This flag defaults to `active` because `refetchActive` defaulted to `true`. This means we also need a way to tell `invalidateQueries` to not refetch at all, which is why a fourth option (`none`) is also allowed here.
The `invalidateQueries` method can be used to invalidate and refetch single or multiple queries in the cache based on their query keys or any other functionally accessible property/state of the query. By default, all matching queries are immediately marked as invalid and active queries are refetched in the background.
270
270
271
-
- If you **do not want active queries to refetch**, and simply be marked as invalid, you can use the `refetchActive: false` option.
272
-
- If you **want inactive queries to refetch** as well, use the `refetchInactive: true` option
271
+
- If you **do not want active queries to refetch**, and simply be marked as invalid, you can use the `refetchType: 'none'` option.
272
+
- If you **want inactive queries to refetch** as well, use the `refetchTye: 'all'` option
- When set to `false`, queries that match the refetch predicate and are actively being rendered via `useQuery` and friends will NOT be refetched in the background, and only marked as invalid.
289
-
-`refetchInactive: Boolean`
290
-
-Defaults to `false`
291
-
- When set to `true`, queries that match the refetch predicate and are not being rendered via `useQuery` and friends will be both marked as invalid and also refetched in the background
- When set to `active`, only queries that match the refetch predicate and are actively being rendered via `useQuery` and friends will be refetched in the background.
288
+
- When set to `inactive`, only queries that match the refetch predicate and are NOT actively being rendered via `useQuery` and friends will be refetched in the background.
289
+
-When set to `all`, all queries that match the refetch predicate will be refetched in the background.
290
+
- When set to `none`, no queries will be refetched, and those that match the refetch predicate will be marked as invalid only.
0 commit comments