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(QueryObserver): track queries as default (#2987)
* feat(Query Options): remove notifyOnChangePropsExclusion
- remove related code from queryObserver
- remove type def
- remove related tests
* docs(Query Options): update notifyOnChangePropsExclusion sections
- remove from api references
- add to v4 migration guide
* feat(QueryObserver): "tracked" as default behavior
- remove "tracked" completely if notifyOnChangeProps is not defined, behave as v3 "tracked"
- add `notifyOnChangeProps: 'all' to opt out of the smart tracking
TODO: Now that default behavior has changed, work out the failed tests. Which parts to change for current ones and possibly write new ones.
* test(useQuery): adjust tests to pass for notifyOnChangeProps udpate
* test(useInfiniteQuery): adjust tests to pass for notifyOnChangeProps udpate
* test(QueryResetErrorBoundary): adjust tests to pass for notifyOnChangeProps udpate
* refactor(QueryObserver): use nullish coalescing operator
much cleaner than the negated if I started with
* test(QueryResetErrorBoundary): remove "tracked" from test
* revert: test(QueryResetErrorBoundary): adjust tests to pass for notifyOnChaneProps udpate
This reverts commit a34b472.
The changes are not necessary after PR #2993 fix.
* refactor(QueryObserver): combine prop checks
* docs(notifyOnChangeProps): update docs to reflect new api
Copy file name to clipboardExpand all lines: docs/src/pages/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
@@ -64,7 +64,7 @@ Feature/Capability Key:
64
64
65
65
> **<sup>1</sup> Lagged Query Data** - React Query provides a way to continue to see an existing query's data while the next query loads (similar to the same UX that suspense will soon provide natively). This is extremely important when writing pagination UIs or infinite loading UIs where you do not want to show a hard loading state whenever a new query is requested. Other libraries do not have this capability and render a hard loading state for the new query (unless it has been prefetched), while the new query loads.
66
66
67
-
> **<sup>2</sup> Render Optimization** - React Query has excellent rendering performance. It will only re-render your components when a query is updated. For example because it has new data, or to indicate it is fetching. React Query also batches updates together to make sure your application only re-renders once when multiple components are using the same query. If you are only interested in the `data` or `error` properties, you can reduce the number of renders even more by setting `notifyOnChangeProps` to `['data', 'error']`. Set `notifyOnChangeProps: 'tracked'` to automatically track which fields are accessed and only re-render if one of them changes.
67
+
> **<sup>2</sup> Render Optimization** - React Query has excellent rendering performance. By default, it will automatically track which fields are accessed and only re-render if one of them changes. If you would like to opt-out of this optimization, setting `notifyOnChangeProps` to `'all'` will re-render your components whenever the query is updated. For example because it has new data, or to indicate it is fetching. React Query also batches updates together to make sure your application only re-renders once when multiple components are using the same query. If you are only interested in the `data` or `error` properties, you can reduce the number of renders even more by setting `notifyOnChangeProps` to `['data', 'error']`.
68
68
69
69
> **<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.
Copy file name to clipboardExpand all lines: docs/src/pages/guides/migrating-to-react-query-4.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,16 @@ With version [3.22.0](https://github.com/tannerlinsley/react-query/releases/tag/
27
27
+ import { dehydrate, hydrate, useHydrate, Hydrate } from 'react-query'
28
28
```
29
29
30
+
### `notifyOnChangeProps` property no longer accepts `"tracked"` as a value
31
+
32
+
The `notifyOnChangeProps` option no longer accepts a `"tracked"` value. Instead, `useQuery` defaults to tracking properties. All queries using `notifyOnChangeProps: "tracked"` should be updated by removing this option.
33
+
34
+
If you would like to bypass this in any queries to emulate the v3 default behavior of re-rendering whenever a query changes, `notifyOnChangeProps` now accepts an `"all"` value to opt-out of the default smart tracking optimization.
35
+
36
+
### `notifyOnChangePropsExclusion` has been removed
37
+
38
+
In v4, `notifyOnChangeProps` defaults to the `"tracked"` behavior of v3 instead of `undefined`. Now that `"tracked"` is the default behavior for v4, it no longer makes sense to include this config option.
39
+
30
40
### Consistent behavior for `cancelRefetch`
31
41
32
42
The `cancelRefetch` can be passed to all functions that imperatively fetch a query, namely:
Copy file name to clipboardExpand all lines: docs/src/pages/reference/QueryClient.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
@@ -91,7 +91,7 @@ try {
91
91
92
92
**Options**
93
93
94
-
The options for `fetchQuery` are exactly the same as those of [`useQuery`](./useQuery), except the following: `enabled, refetchInterval, refetchIntervalInBackground, refetchOnWindowFocus, refetchOnReconnect, notifyOnChangeProps, notifyOnChangePropsExclusions, onSuccess, onError, onSettled, useErrorBoundary, select, suspense, keepPreviousData, placeholderData`; which are strictly for useQuery and useInfiniteQuery. You can check the [source code](https://github.com/tannerlinsley/react-query/blob/361935a12cec6f36d0bd6ba12e84136c405047c5/src/core/types.ts#L83) for more clarity.
94
+
The options for `fetchQuery` are exactly the same as those of [`useQuery`](./useQuery), except the following: `enabled, refetchInterval, refetchIntervalInBackground, refetchOnWindowFocus, refetchOnReconnect, notifyOnChangeProps, onSuccess, onError, onSettled, useErrorBoundary, select, suspense, keepPreviousData, placeholderData`; which are strictly for useQuery and useInfiniteQuery. You can check the [source code](https://github.com/tannerlinsley/react-query/blob/361935a12cec6f36d0bd6ba12e84136c405047c5/src/core/types.ts#L83) for more clarity.
0 commit comments