Side Effects with useEffect
Synchronise a component with the outside world: how effects run, what the dependency array really means, why cleanup matters, and when not to use an effect at all.
- Level
- Intermediate
- Chapters
- 4
- Exercises
- 1
- Reading time
- 18 min
What you will cover
- 1. What an Effect IsSynchronising with systems outside React, and when the effect body runs.
- 2. The Dependency ArrayThe three forms of the second argument and what each one means.
- 3. CleanupReturning a teardown function, and why React runs it more often than you expect.
- 4. When Not to Use an EffectThe four cases where an effect is the wrong tool, and what to do instead.
Up next after this one: Refs with useRef