Class Components and Legacy Lifecycle Methods
Understand class component lifecycle methods for maintaining legacy codebases, and how they map conceptually to hooks.
Before hooks, all stateful React components were written as classes extending React.Component, using named lifecycle methods to hook into the mount/update/unmount phases: componentDidMount (runs once after the initial render, commonly used for data fetching or subscriptions), componentDidUpdate(prevProps, prevState) (runs after every re-render, given the previous props/state for comparison), and componentWillUnmount (runs just before the component is removed, for cleanup).
Class lifecycle methods are like named stops on a scheduled train route — 'arrival' (componentDidMount), 'in-transit adjustments' (componentDidUpdate), and 'final departure' (componentWillUnmount) — each a fixed, separately named station, whereas hooks-based effects are more like a standing instruction to 'keep this thing synchronized with these specific conditions,' regardless of which named phase of the journey it happens to correspond to.