Comparation

Class ComponentFunction Component

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.

componentDidMount

useEffect(() => {
  // Your code here
}, []);

componentDidUpdate

useEffect(() => {
  // Your code here
}, [yourDependency]);

componentWillUnmount

useEffect(() => {
  // componentWillUnmount
  return () => {
     // Your code here
  }
}, [yourDependency]);

getSnapshotBeforeUpdate

There are no Hook equivalents for this method yet, but they will be added soon.

componentDidCatch

There are no Hook equivalents for this method yet, but they will be added soon.

getDerivedStateFromError

There are no Hook equivalents for this method yet, but they will be added soon.

Last updated