Hooks are new features incorporated into React 16.8. and the newer versions. They basically help you use React features without writing a class.
I...
For further actions, you may consider blocking this person and/or reporting abuse
It's an easy way of explaining and understanding how
useEffect
works. But I agree. Maybe it would be better to create an example using something like window dimensions which from my point of view requires theuseEffect
hook. Needed for adding and removing the event listener.useWindowDimensions custom hook
From React docs
The clean-up function runs before the component is removed from the UI to prevent memory leaks. Additionally, if a component renders multiple times (as they typically do), the previous effect is cleaned up before executing the next effect.
Please have a look over the updated documentation:
Thank you!
For those just getting started with useEffect, I highly suggest using something that provides intellisense about the hook's dependency array.
It's straightforward once you're used to the concept, but in the beginning, it will save you lots of headaches.
Thanks for the explanation. But I still struggling to understand this concept. Can you explain it with a more practical app or example. Please share if you have any YT link etc.
I think this Youtube video by WebDevSimplified will help you get a clearer picture.
youtu.be/0ZJgIjIuY7U
Nice article, I like it :D
I'm glad you found it useful.
I've recently written a post about useEffect, specifically about the dependency array. Because I tend to forget how to use it right. You find it here if you like: chrisko.io/posts/useEffect-hook-de...
It was an amazing read..
Thanks for your addition. This isn't a sophisticated example,it was just to help beginners up and running.