← BYTES
React.js·Intermediate·Ref: 4.2.1

Compared to the class-component lifecycle, when does a `useEffect` with no dependency array run relative to `componentDidMount` and `componentDidUpdate`?

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

a.It only ever behaves like `componentDidMount`, never like `componentDidUpdate`
b.It runs after every render, which covers both the initial mount AND every subsequent update -- effectively combining what `componentDidMount` and `componentDidUpdate` did separately
c.It runs before the component renders, unlike either lifecycle method
d.It is completely unrelated to the class lifecycle and has no analogue
With no dependency array, the effect callback runs after every commit, including the first one -- so a single `useEffect` naturally subsumes the job that `componentDidMount` plus `componentDidUpdate` used to split across two separate methods.

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#BYTES421#Reactjs