Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

react/no-unused-class-component-methods

Disallow methods and properties of a class component that the class never uses

A handler that's no longer wired to any element stays in the class and looks like it still matters. This rule reports a method or a property of a class component, or of a createReactClass component, that's never read through this in the same component.

Lifecycle methods such as render and componentDidMount, state, and static members are never reported.

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"react/no-unused-class-component-methods" = "error" # or "warn"

Examples

Reported:

class SearchBox extends React.Component {
  timeout = 300;

  handleChange(event) {
    this.props.onSearch(event.target.value);
  }

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

Not reported:

class SearchBox extends React.Component {
  timeout = 300;

  handleChange = event => {
    setTimeout(() => this.props.onSearch(event.target.value), this.timeout);
  };

  render() {
    return <input onChange={this.handleChange} />;
  }
}

When not to use it

The rule only looks inside the component. If a parent calls a method through a ref, such as searchBox.current.focus(), the method is reported even though it's used.