DEV Community

Discussion on: Replace lifecycle with hooks in React

Collapse
 
avxkim profile image
Alexander Kim

If you use useEffect with empty deps array, ESLint would throw an error, that you have to add all dependencies, or omit deps array at all. So, it's not a replacement for componentdidmount lifecycle. What do you use yourself, when you need to do something, only when your component is mounted?

Collapse
 
svgpubs profile image
svgpubs

I created an account just to like your comment. I am stuck because my useEffect hook relies on local state. Since I need to add local state in the dependency array for the function to work, I cannot use it as a stand-in for componentDidUnmount.

Where is the onUnmount hook?

Collapse
 
arnabsen1729 profile image
Arnab Sen

Take a look at this thread once: github.com/facebook/react/issues/1... Might be helpful

Collapse
 
mujaddadi profile image
Taha Hassan Mujaddadi

That's problem of ESlint. You can easily change the rule by the way.

Collapse
 
avxkim profile image
Alexander Kim

Of course you can, but it's not recommended.