Common Pitfalls: Stale Closures & Missing Deps
Avoid stale closures and missing dependencies; learn safe patterns to read the latest values inside effects and timers.
Pitfalls overview
Goal: Spot and fix two common issues: stale closures (effect sees old values) and missing deps (effect does not re-run when it should).
Stale closure concept
A stale closure happens when a function (timer/listener) captures an old value from a previous render.
- Effect doesn’t see latest state
- Timer increments wrong
All lessons in this course
- Effects vs Render, Dependencies & Cleanup
- Common Pitfalls: Stale Closures & Missing Deps
- Fetching Basics in Effects (Abort & Cleanup)