Open History to see the last commit
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`.