I read How to sync props to state using React hooks : setState() that is basically about how to mimic getDerivedStateFromProps
in a functional component. The accepted answer said to use useEffect
. But the problem is that this would cause an extra unnecessary render, as some comments pointed out. So I wanted to ask a separate question about specifically whether useEffect
should be used in this case.
Asked
Active
Viewed 529 times
0

Joe C.
- 397
- 4
- 15
-
2Can you provide an example of what kind of derived state you want? This just sounds like redundant state – Nick Aug 15 '22 at 00:00
-
Does it need to be state or do you just need to memoize something with `useMemo`? Re-renders are meant to be insignificant (most of the time) for function components as long as they are not logically inefficient. This might also be helpful [https://stackoverflow.com/a/66057592/4364635](https://stackoverflow.com/a/66057592/4364635) – Jacob Smit Aug 15 '22 at 00:47