ReactIntermediate#lifecycle#hooks

How does the component lifecycle map to hooks?

componentDidMount maps to useEffect with [], componentDidUpdate to useEffect with dependencies, and componentWillUnmount to the cleanup function returned from useEffect.

Example
useEffect(() => {
  subscribe();            // mount
  return () => unsubscribe(); // unmount
}, []);
useEffect(() => sync(id), [id]); // update

Related Questions

1
ReactAdvanced#performance

What is lazy loading and code splitting in React?

Open
2
ReactAdvanced#performance#data

What is Suspense?

Open
3
ReactAdvanced#patterns

What are higher-order components (HOCs)?

Open