← BYTES
React.js·Intermediate·Ref: 4.2.3

What is the purpose of the function you can optionally return from inside a `useEffect` callback?

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

a.It becomes the new return value of the component
b.Returning a function from useEffect is a syntax error
c.It replaces the dependency array
d.It is a cleanup function that React calls before the effect re-runs, and when the component unmounts
If an effect returns a function, React treats it as cleanup logic -- it's invoked right before the effect runs again (if dependencies changed) and once more when the component unmounts, which is the standard place to tear down subscriptions, timers, or event listeners that the effect set up.

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