← BYTES
React.js·Intermediate·Ref: 4.2.15

In a function component, what's the equivalent of a class component's `componentDidUpdate` (code that should run after specific props or state change, but not on the very first render)?

Have a question about this video? Mention reference 4.2.15 when you contact us.

a.`useEffect` with no dependency array at all
b.There is no way to express this in function components
c.`useState`'s setter function itself runs this code automatically
d.`useEffect` with a dependency array listing the specific values to watch, combined with a ref-based check to skip the very first run if you truly need to exclude it
A dependency array scoped to just the values you care about makes the effect re-run only when those change (which already covers "update" semantics reasonably well); if you specifically need to skip the very first mount-time run too, that typically needs an extra ref flag, since React has no built-in "didUpdate-only" hook.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES4215#Reactjs