Skip to main content

react/noRedundantShouldComponentUpdate

flag shouldComponentUpdate when extending PureComponent

ESLint Equivalent: no-redundant-should-component-update

Examples

Invalid

class Hello extends React.PureComponent {
	shouldComponentUpdate() {}
}

 file.tsx:1 lint/react/noRedundantShouldComponentUpdate ━━━━━━━━━━━━━━━━━━━

  Do not implement shouldComponentUpdate when extending 
    React.PureComponent.

  > 1class Hello extends React.PureComponent {
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  > 2  shouldComponentUpdate() {}
  > 3}
     ^

  When the shouldComponentUpdate method is implemented, extending
    React.PureComponent provides no benefit.


class Hello extends PureComponent {
	shouldComponentUpdate() {}
}

 file.tsx:1 lint/react/noRedundantShouldComponentUpdate ━━━━━━━━━━━━━━━━━━━

  Do not implement shouldComponentUpdate when extending 
    React.PureComponent.

  > 1class Hello extends PureComponent {
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  > 2  shouldComponentUpdate() {}
  > 3}
     ^

  When the shouldComponentUpdate method is implemented, extending
    React.PureComponent provides no benefit.

Valid

class Hello extends React.PureComponent {
	componentDidMount() {}
}
class Hello extends PureComponent {
	componentDidMount() {}
}