Skip to content

Commit 10215b0

Browse files
docs(notifyOnChangeProps): update docs to reflect new api
1 parent 0f4bf90 commit 10215b0

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

docs/src/pages/comparison.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Feature/Capability Key:
6464

6565
> **<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.
6666
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']`.
6868
6969
> **<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.
7070

docs/src/pages/guides/migrating-to-react-query-4.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ With version [3.22.0](https://github.com/tannerlinsley/react-query/releases/tag/
2727
+ import { dehydrate, hydrate, useHydrate, Hydrate } from 'react-query'
2828
```
2929

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+
3036
### `notifyOnChangePropsExclusion` has been removed
3137

3238
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.

docs/src/pages/reference/useQuery.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ const result = useQuery({
124124
- If set to `true`, the query will refetch on reconnect if the data is stale.
125125
- If set to `false`, the query will not refetch on reconnect.
126126
- If set to `"always"`, the query will always refetch on reconnect.
127-
- `notifyOnChangeProps: string[] | "tracked"`
127+
- `notifyOnChangeProps: string[] | "all"`
128128
- Optional
129129
- If set, the component will only re-render if any of the listed properties change.
130130
- If set to `['data', 'error']` for example, the component will only re-render when the `data` or `error` properties change.
131-
- If set to `"tracked"`, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.
131+
- If set to `"all"`, the component will opt-out of smart tracking and re-render whenever a query is updated.
132+
- By default, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.
132133
- `onSuccess: (data: TData) => void`
133134
- Optional
134135
- This function will fire any time the query successfully fetches new data.

src/core/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ export interface QueryObserverOptions<
154154
/**
155155
* If set, the component will only re-render if any of the listed properties change.
156156
* When set to `['data', 'error']`, the component will only re-render when the `data` or `error` properties change.
157-
* When set to `tracked`, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.
157+
* When set to `'all'`, the component will re-render whenever a query is updated.
158+
* By default, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.
158159
*/
159160
notifyOnChangeProps?: Array<keyof InfiniteQueryObserverResult> | 'all'
160161
/**

0 commit comments

Comments
 (0)