Rewrite `PureComponent` ⇒ `Component`

JavaScript pattern

If a PureComponent has the shouldComponentUpdate method, convert it to a regular Component.

React.PureComponent provides an implementation for shouldComponentUpdate() which compares props by reference to determine if they have changed. If you overwrite it with your own implementation, it doesn't make sense to extend React.PureComponent.


Apply with the Grit CLI
grit apply convert_PureComponent_to_Component

Convert to React.Component when extending React.PureComponent

BEFORE
class Foo extends React.PureComponent {
  customMethod() {}

  shouldComponentUpdate() {}

  render() {
    return <Hello />;
  }
}

class Foo extends React.Component {
  customMethod() {}

  shouldComponentUpdate() {}

  render() {
    return <Hello />;
  }
}
AFTER
class Foo extends React.Component {
  customMethod() {}

  shouldComponentUpdate() {}

  render() {
    return <Hello />;
  }
}

class Foo extends React.Component {
  customMethod() {}

  shouldComponentUpdate() {}

  render() {
    return <Hello />;
  }
}

Convert to Component when extending destructured PureComponent

BEFORE
class Foo extends PureComponent {
  customMethod() {}

  shouldComponentUpdate() {}

  render() {
    return <Hello />;
  }
}
AFTER
class Foo extends Component {
  customMethod() {}

  shouldComponentUpdate() {}

  render() {
    return <Hello />;
  }
}