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?
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.
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?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?Take a look at this thread once: github.com/facebook/react/issues/1... Might be helpful
That's problem of ESlint. You can easily change the rule by the way.
Of course you can, but it's not recommended.