@tlakomy one way to think about it is that useEffect is a way to synchronize React with some external system (network, subscription, DOM). if you don’t have any external system and just try to manage your data flow with useEffect, you’re gonna have all these problems.
A passionate frontend Engineer proficient in frontend technologies. Actively involved in providing complex information to readers in a way that they can understand and apply.
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 the useEffect hook. Needed for adding and removing the event listener.
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.
A passionate frontend Engineer proficient in frontend technologies. Actively involved in providing complex information to readers in a way that they can understand and apply.
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...
A passionate frontend Engineer proficient in frontend technologies. Actively involved in providing complex information to readers in a way that they can understand and apply.
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.
A passionate frontend Engineer proficient in frontend technologies. Actively involved in providing complex information to readers in a way that they can understand and apply.
A passionate frontend Engineer proficient in frontend technologies. Actively involved in providing complex information to readers in a way that they can understand and apply.
Please have a look over the updated documentation:
Thank you!
It's an easy way of explaining and understanding how
useEffectworks. But I agree. Maybe it would be better to create an example using something like window dimensions which from my point of view requires theuseEffecthook. 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.
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.
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 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
Thanks for your addition. This isn't a sophisticated example,it was just to help beginners up and running.