Skip to main content

Class Components and the Component Lifecycle

Learn Class Components and the Component Lifecycle (Phase 2 · JSX and Components (Essential), ReactJS) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Class components (legacy, but still in many codebases) • Before hooks, stateful components were classes extending React.Component , with this.props , this.state , this.setState() and a render() method. • New code should use function components with hooks, but you must read class components in older projects. Error boundaries still require a class. • setState merges the update into state and is asynchronous/batched : use setState(prev => ...) when the new state depends on the old.

More lessons in Phase 2 · JSX and Components (Essential)