File tree Expand file tree Collapse file tree 1 file changed +3
-11
lines changed Expand file tree Collapse file tree 1 file changed +3
-11
lines changed Original file line number Diff line number Diff line change @@ -10,40 +10,32 @@ This rule aims at reminding developers to add the corrisponding removeEventListe
10
10
11
11
Examples of ** incorrect** code for this rule:
12
12
13
- ``` js
14
-
13
+ ``` jsx
15
14
// Missing a matching removeEventListener.
16
-
17
15
useEffect (() => {
18
16
window .addEventListener (" keydown" , handleUserKeyPress);
19
17
return () => {
20
18
doThis ();
21
19
};
22
20
}, [])
23
-
24
21
```
25
22
26
- ``` js
27
-
23
+ ``` jsx
28
24
// Missing a cleanup function for the addEventListener.
29
-
30
25
useEffect (() => {
31
26
window .addEventListener (" keydown" , handleUserKeyPress);
32
27
}, [])
33
-
34
28
```
35
29
36
30
Examples of ** correct** code for this rule:
37
31
38
- ``` js
39
-
32
+ ``` jsx
40
33
useEffect (() => {
41
34
window .addEventListener (" keydown" , handleUserKeyPress);
42
35
return () => {
43
36
window .removeEventListener (" keydown" , handleUserKeyPress);
44
37
};
45
38
}, []);
46
-
47
39
```
48
40
49
41
## When Not To Use It
You can’t perform that action at this time.
0 commit comments