Skip to content

Pure Component

In one line

A pure component is a class component that implements shouldComponentUpdate with a shallow prop and state comparison to skip unnecessary re-renders.

In simple words

React.PureComponent is a class component variant that automatically implements shouldComponentUpdate with a shallow comparison of props and state. If the shallow comparison says nothing changed, the component skips re-rendering.

This is the class component equivalent of React.memo for function components. It prevents re-renders when the parent re-renders but the props/state are shallowly equal.

Caveat: shallow comparison only checks one level deep. If you pass a new object or array with the same contents, the shallow comparison sees a different reference and re-renders anyway. For nested objects, you need deep comparison (which is expensive) or immutable data structures.

Example

jsx
class MyComponent extends React.PureComponent {
  render() {
    return <div>{this.props.value}</div>;
  }
}

// Only re-renders when this.props.value changes (shallowly).

PureComponent does a shallow comparison of props. If value is the same primitive, the component skips re-rendering.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary