Commit 5c18771
committed
fix: use functional updater in MemoCounter to avoid stale closure
setNum(num + 1) captures num from the render closure, which goes
stale when React.memo skips re-renders. Using setNum(n => n + 1)
always reads the latest state.1 parent 0a7df67 commit 5c18771
1 file changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
| 288 | + | |
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| |||
0 commit comments