React · Junior · Question 24 of 75
When does the effect useEffect(() => { ... }, []) run?
- 1Before every render of the component, to prepare data
- ✓Correct answer: After mounting (twice in dev with StrictMode)
- 3Only when the component unmounts, like
componentWillUnmount
Explanation
An empty dependency array means "synchronize after mounting". Effects always run after painting, not before. In development, StrictMode mounts, unmounts and mounts the component again to verify that the effect's cleanup is written correctly.