Day 7 of 14 30 minuseEffectCleanupDependencies
Synchronise components with things outside React, like timers, the document title, event listeners and network requests. Learn the dependency array, cleanup functions, why effects run twice in development, and when you don't need an effect at all.
By the end of today you can
- Explain what an effect is and when it runs
- Control when an effect re-runs with the dependency array
- Write cleanup functions for timers, listeners and subscriptions
- Explain why Strict Mode runs effects twice in development
- Recognise code that doesn't need an effect
What's inside
- 7 sections
- 2 diagrams and mind maps
- 4 code examples you can run
- 5-question quiz
- 1Your first effect
- 2The dependency array
- 3Cleanup
- 4Listening to the browser
- 5Effects that depend on props
- 6Why effects run twice in development
- 7You might not need an effect
Sign in free to read this lesson
Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.
Sign in free