Home

ReactPureComponent

React.PureComponent is a base class in the React library that extends React.Component and provides a built-in optimization for rendering. It implements a default shouldComponentUpdate method that performs a shallow comparison of the current props and state with the next props and state. If the shallow comparison reports no changes, React skips re-rendering the component and its subtree, which can reduce unnecessary updates.

Usage typically involves extending PureComponent rather than Component, for example class MyComponent extends React.PureComponent. The canonical

How it works and when to use it: PureComponent relies on shallow equality for props and state.

Caveats: Since the check is shallow, deep mutations may not trigger a re-render. Mutating nested data without

Relation to other patterns: For functional components, a similar effect is achieved with React.memo. PureComponent is

name
is
React.PureComponent;
some
discussions
may
refer
to
it
informally
as
ReactPureComponent.
Primitive
values
are
compared
by
value,
while
objects
and
arrays
are
compared
by
reference.
This
makes
PureComponent
effective
when
your
data
is
treated
as
immutable
or
when
you
replace
objects
and
arrays
rather
than
mutating
them
in
place.
It
can
improve
performance
for
frequently
rendered
components
whose
props/state
do
not
change
often.
changing
references
can
lead
to
stale
output.
If
your
component
depends
on
deep
changes
or
complex
equality
logic,
you
may
need
to
implement
shouldComponentUpdate
yourself
or
use
other
optimization
strategies.
a
class-based
alternative
that
complements
immutable
data
patterns
and
can
simplify
performance
tuning
in
class
components.