Effects, refs and custom Hooks
useEffect with dependencies and cleanup, refs for DOM access and silent values, and custom Hooks for reusable logic.
About 5 hours of study
Learning objectives
- Run and clean up effects
- Use refs for focus and timer ids
- Extract custom Hooks
Lessons
- 1
Effects: syncing with the outside world Intermediate
useEffect for work that must happen after rendering: timers, the document title, subscriptions; dependency arrays, cleanup functions, and when you do not need an effect at all.
- 2
Refs: remembering without rendering Intermediate
useRef for values that must survive renders without causing them, refs to DOM elements for focus and measurement, storing timer ids, and when to use a ref instead of state.
- 3
Custom Hooks: reusing stateful logic Advanced
Extracting state and effects into functions whose names start with use, what they may return, how each call gets its own state, and the rules of Hooks.
Module practice
- React: Keep the title in stepEasy
- React: A stopwatch with a cleaned-up intervalMedium
- React: Search after the typing stopsHard
- React: Focus and clear a fieldEasy
- React: A lap timer with a ref for the intervalMedium
- React: Move focus through a formHard
- React: Write useToggleEasy
- React: A counter Hook with limitsMedium
- React: A form HookHard