How do lifecycle methods correspond to Hooks?

Posted by Prem Tiwari | Updated on
  • constructor: Function components don’t need a constructor. You can initialize the state in the useState call. If computing the initial state is expensive, you can pass a function to useState.
  • getDerivedStateFromProps: Schedule an update while rendering instead.
  • shouldComponentUpdate: See React.memo below.
  • render: This is the function component body itself.
  • componentDidMountcomponentDidUpdatecomponentWillUnmount: The useEffect Hook can express all combinations of these (including less common cases).
  • getSnapshotBeforeUpdatecomponentDidCatch and getDerivedStateFromError: There are no Hook equivalents for these methods yet, but they will be added soon.

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers