Browse Source

fix: grammar error (#5760)

main
Zambrano 2 years ago
committed by GitHub
parent
commit
b40432a116
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/content/learn/separating-events-from-effects.md

2
src/content/learn/separating-events-from-effects.md

@ -790,7 +790,7 @@ body {
</Sandpack>
The problem with the this code is in suppressing the dependency linter. If you remove the suppression, you'll see that this Effect should depend on the `handleMove` function. This makes sense: `handleMove` is declared inside the component body, which makes it a reactive value. Every reactive value must be specified as a dependency, or it can potentially get stale over time!
The problem with this code is in suppressing the dependency linter. If you remove the suppression, you'll see that this Effect should depend on the `handleMove` function. This makes sense: `handleMove` is declared inside the component body, which makes it a reactive value. Every reactive value must be specified as a dependency, or it can potentially get stale over time!
The author of the original code has "lied" to React by saying that the Effect does not depend (`[]`) on any reactive values. This is why React did not re-synchronize the Effect after `canMove` has changed (and `handleMove` with it). Because React did not re-synchronize the Effect, the `handleMove` attached as a listener is the `handleMove` function created during the initial render. During the initial render, `canMove` was `true`, which is why `handleMove` from the initial render will forever see that value.

Loading…
Cancel
Save