React·100 questions

What are stale closures in hooks and how to avoid them?

Answer
Closure can hold onto old values.
Commonly occurs in setInterval/handlers.
Add dependencies or use functional setState.
Store current value in useRef.
Do not ignore deps for linter silence.
Was this answer helpful?

More questions in this topic

Related questions from other topics