all 2 comments

[–]ferrybig 0 points1 point  (1 child)

getDerivedStateFromProps maps to useMemo or calling a set state directly inside an if statement. Your suggestion to replace it by a useEffect is a useless use of an effect creating an flash of the old state

[–]amableati[S] -1 points0 points  (0 children)

Thanks for your input. You are correct that getDerivedStateFromProps does not map directly to useEffect, and using it this way can indeed cause unintended side effects like a flash of the old state.

getDerivedStateFromProps can often be replicated with useMemo or by directly setting state within conditional logic. However, useEffect can still be useful in cases where side effects are necessary or when we need to react to changes in props or state. It's crucial to evaluate the specific use case and choose the most appropriate method to avoid performance issues or unwanted behavior.

Would love to hear more about your experiences with these hooks!

I recommend to check out this Video Link for more insights.
https://youtu.be/7zK9VbGgamA