React · Lesson 45 of 120
Effects Quiz
Test yourself.
Let's review effects and refs. Pause after each question, and answer before I do.
- Effects quiz
- Pause and think
- Then check
Question 1
When does an effect with an empty dependency array run? Once, after the first render.
Quick check
useEffect(fn, []) runs:
Question 2
How do you stop an interval when the component goes away? Return a cleanup function that clears it.
Quick check
To stop a timer, the effect should:
Question 3
Should you use an effect to calculate a filtered list? No. Calculate it during render.
Quick check
A filtered list should be:
Question 4
Does changing ref dot current re-render the component? No, it doesn't.
Quick check
Changing ref.current:
Summary
Well done. Next, a new section on context.
Key takeaways- Dependencies
- Cleanup
- Refs
Next up: Context — no more prop drilling