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

replaceEqualDeep.md

53 lines921 Bytes

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