Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

replaceEqualDeep.md

50 lines847 Bytes

1---
2id: replaceEqualDeep
3title: replaceEqualDeep
4---
5​
6```ts
7function replaceEqualDeep<T>(
8 a: unknown,
9 b: T,
10 depth?: number): T;
11```
12​
13Defined in: [packages/query-core/src/utils.ts:388](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L388)
14​
15This function returns `a` if `b` is deeply equal.
16If not, it will replace any deeply equal children of `b` with those of `a`.
17This can be used for structural sharing between JSON values for example.
18​
19## Type Parameters
20​
21### T
22​
23`T`
24​
25## Parameters
26​
27### a
28​
29`unknown`
30​
31The previous value, whose deeply equal parts are reused.
32​
33### b
34​
35`T`
36​
37The new value.
38​
39### depth?
40​
41`number`
42​
43The current recursion depth. Past a depth of `500`, `b` is returned as is.
44​
45## Returns
46​
47`T`
48​
49`a` if `b` is deeply equal to it, otherwise `b` with its deeply equal parts replaced by
50those of `a`.