IMHO it's best to completely forget the old lifecycle methods. useEffect is its own thing and I've seen a lot of unintended behavior, bugs and performance issues in apps that tried to use the useEffect hook to replace their old lifecycle hooks. useEffect is intended for side effects that need to run during rendering. The most common mistake for example is people doing state updates in useEffect, which results in another render, which can result in unexpected app behavior bad performance or even crashes due to infinite loops. 99% of the time what people put in useEffect should really have been a useMemo instead.
Yes useEffect is it's own thing and not 100% the same as the old lifecycle methods, although the comparison still stands as a lot of things that would have been done in the old lifecycle methods are now done in useEffect.
I don't agree that updating state in useEffect is a bad thing, the re-render that is caused by updating state is often precisely what is wanted, such as if you fetch some data you probably want to display that data and therefore want the UI to re-render. If you don't want it to re-render then use a ref to store that data.
I don't really get what you mean by using useMemo instead of useEffect, could you provide an example of something that people often put into useEffect that should be using useMemo instead? Or do you mean that many people don't memoize a dependency therefore causing useEffect to fire unnecessarily?
IMHO it's best to completely forget the old lifecycle methods. useEffect is its own thing and I've seen a lot of unintended behavior, bugs and performance issues in apps that tried to use the useEffect hook to replace their old lifecycle hooks. useEffect is intended for side effects that need to run during rendering. The most common mistake for example is people doing state updates in useEffect, which results in another render, which can result in unexpected app behavior bad performance or even crashes due to infinite loops. 99% of the time what people put in useEffect should really have been a useMemo instead.
Yes useEffect is it's own thing and not 100% the same as the old lifecycle methods, although the comparison still stands as a lot of things that would have been done in the old lifecycle methods are now done in useEffect.
I don't agree that updating state in useEffect is a bad thing, the re-render that is caused by updating state is often precisely what is wanted, such as if you fetch some data you probably want to display that data and therefore want the UI to re-render. If you don't want it to re-render then use a ref to store that data.
I don't really get what you mean by using useMemo instead of useEffect, could you provide an example of something that people often put into useEffect that should be using useMemo instead? Or do you mean that many people don't memoize a dependency therefore causing useEffect to fire unnecessarily?
I see this happen a lot:
Infact some people use that pattern by default :(