Mutable Refs for Timers & IDs
Use refs to hold timer handles, debounce timeouts, and simple unique ids that survive renders without causing re-renders.
Why mutable refs?
Aim: Keep timer handles, debounce timeouts, and simple ids in useRef so they survive renders without causing new ones.
Rules and patterns
Rules:
- Put implementation details (ids, handles) in refs.
- Use functional setState inside timers.
- Clear timers in cleanup to avoid leaks.
All lessons in this course
- Persisting Values Without Re-render
- Accessing DOM Nodes, Measuring & Focusing
- Mutable Refs for Timers & IDs