A custom implementation for the shouldComponentUpdate()
method as part of the React component lifecycle is not required.
I understand it's a boolean function that determines whether render()
will be called upon changes in component props
and state
, and there are mixins
like PureRenderMixin which implements the shouldComponentUpdate()
If no custom implementation nor mixins are provided. What's the default implementation and behavior?
As of React v0.13 and v0.14 the default implementation equals to null
and as per this logic:
var shouldUpdate =
this._pendingForceUpdate ||
!inst.shouldComponentUpdate ||
inst.shouldComponentUpdate(nextProps, nextState, nextContext);
the component is updated every render cycle (since !inst.shouldComponentUpdate
evaluates to true
).
Defaults to true.
The default behaviour is to re-render on every state change, and in the vast majority of cases, you should rely on the default behaviour.
shouldComponentUpdate() is invoked before rendering when new props or state are being received. Defaults to true. This method is not called for the initial render or when forceUpdate() is used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With