Before you start using
getDerivedStateFromProps, please go through the documentation and You Probably Don't Need Derived State. Derived State can be easily achieved using hooks which can also help set up memoization easily.
Here are a few ways in which you can annotate
- If you have explicitly typed your derived state and want to make sure that the return value from
getDerivedStateFromPropsconforms to it.
- When you want the function's return value to determine your state.
- When you want derived state with other state fields and memoization