AceDevHub
Intermediate React Interview QuestionsIntermediateConcept

React · Question 44

How does the dependency array of useEffect actually work?

Direct answer

The dependency array must include every reactive value read by the Effect; React re-synchronizes when any dependency changes according to Object.is comparison.

Props, state, and values calculated inside the component are reactive values because they can change between renders. If an Effect reads them, they generally belong in its dependency list.

No dependency array
Effect is eligible to run after every commit
Empty array []
Effect has no reactive dependencies
[a, b]
Effect re-synchronizes when a or b changes