9
function Component({x, y, z}) {
10
const a = useMemo(() => {
11
return x?.y.z?.a;
12
+ // error: too precise
13
}, [x?.y.z?.a.b]);
14
const b = useMemo(() => {
15
return x.y.z?.a;
16
+ // ok, not our job to type check nullability
17
}, [x.y.z.a]);
18
const c = useMemo(() => {
19
return x?.y.z.a?.b;
20
+ // error: too precise
21
}, [x?.y.z.a?.b.z]);
22
const d = useMemo(() => {
23
return x?.y?.[(console.log(y), z?.b)];
24
+ // ok
25
}, [x?.y, y, z?.b]);
26
const e = useMemo(() => {
27
const e = [];
28
e.push(x);
29
return e;
30
+ // ok
31
}, [x]);
32
const f = useMemo(() => {
33
return [];
34
+ // error: unnecessary
35
}, [x, y.z, z?.y?.a, UNUSED_GLOBAL]);
36
const ref1 = useRef(null);
37
const ref2 = useRef(null);
40
return () => {
41
return ref.current;
42
};
43
+ // error: ref is a stable type but reactive
44
}, []);
45
return <Stringify results={[a, b, c, d, e, f, cb]} />;
46
}
51
## Error
52
53
```
47
-Found 5 errors:
54
+Found 4 errors:
55
56
Error: Found non-exhaustive dependencies
57
62
6 | const a = useMemo(() => {
63
> 7 | return x?.y.z?.a;
64
| ^^^^^^^^^ Missing dependency `x?.y.z?.a`
58
- 8 | }, [x?.y.z?.a.b]);
59
- 9 | const b = useMemo(() => {
60
- 10 | return x.y.z?.a;
65
+ 8 | // error: too precise
66
+ 9 | }, [x?.y.z?.a.b]);
67
+ 10 | const b = useMemo(() => {
68
69
Error: Found non-exhaustive dependencies
70
71
Missing dependencies can cause a value not to update when those inputs change, resulting in stale UI.
72
66
-error.invalid-exhaustive-deps.ts:10:11
67
- 8 | }, [x?.y.z?.a.b]);
68
- 9 | const b = useMemo(() => {
69
-> 10 | return x.y.z?.a;
70
- | ^^^^^^^^ Missing dependency `x.y.z?.a`
71
- 11 | }, [x.y.z.a]);
72
- 12 | const c = useMemo(() => {
73
- 13 | return x?.y.z.a?.b;
74
-
75
-Error: Found non-exhaustive dependencies
76
-
77
-Missing dependencies can cause a value not to update when those inputs change, resulting in stale UI.
78
-
79
-error.invalid-exhaustive-deps.ts:13:11
80
- 11 | }, [x.y.z.a]);
81
- 12 | const c = useMemo(() => {
82
-> 13 | return x?.y.z.a?.b;
73
+error.invalid-exhaustive-deps.ts:15:11
74
+ 13 | }, [x.y.z.a]);
75
+ 14 | const c = useMemo(() => {
76
+> 15 | return x?.y.z.a?.b;
77
| ^^^^^^^^^^^ Missing dependency `x?.y.z.a?.b`
84
- 14 | }, [x?.y.z.a?.b.z]);
85
- 15 | const d = useMemo(() => {
86
- 16 | return x?.y?.[(console.log(y), z?.b)];
78
+ 16 | // error: too precise
79
+ 17 | }, [x?.y.z.a?.b.z]);
80
+ 18 | const d = useMemo(() => {
81
82
Error: Found unnecessary memoization dependencies
83
84
Unnecessary dependencies can cause a value to update more often than necessary, which can cause effects to run more than expected.
85
92
-error.invalid-exhaustive-deps.ts:25:5
93
- 23 | const f = useMemo(() => {
94
- 24 | return [];
95
-> 25 | }, [x, y.z, z?.y?.a, UNUSED_GLOBAL]);
86
+error.invalid-exhaustive-deps.ts:31:5
87
+ 29 | return [];
88
+ 30 | // error: unnecessary
89
+> 31 | }, [x, y.z, z?.y?.a, UNUSED_GLOBAL]);
90
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unnecessary dependencies `x`, `y.z`, `z?.y?.a`, `UNUSED_GLOBAL`
97
- 26 | const ref1 = useRef(null);
98
- 27 | const ref2 = useRef(null);
99
- 28 | const ref = z ? ref1 : ref2;
91
+ 32 | const ref1 = useRef(null);
92
+ 33 | const ref2 = useRef(null);
93
+ 34 | const ref = z ? ref1 : ref2;
94
95
Error: Found non-exhaustive dependencies
96
97
Missing dependencies can cause a value not to update when those inputs change, resulting in stale UI.
98
105
-error.invalid-exhaustive-deps.ts:31:13
106
- 29 | const cb = useMemo(() => {
107
- 30 | return () => {
108
-> 31 | return ref.current;
99
+error.invalid-exhaustive-deps.ts:37:13
100
+ 35 | const cb = useMemo(() => {
101
+ 36 | return () => {
102
+> 37 | return ref.current;
103
| ^^^ Missing dependency `ref`. Refs, setState functions, and other "stable" values generally do not need to be added as dependencies, but this variable may change over time to point to different values
110
- 32 | };
111
- 33 | }, []);
112
- 34 | return <Stringify results={[a, b, c, d, e, f, cb]} />;
104
+ 38 | };
105
+ 39 | // error: ref is a stable type but reactive
106
+ 40 | }, []);
107
```
108
109
\ No newline at end of file