Try @eslint-react/kit@beta
logoESLint React

no-unused-class-component-members

Warns about unused class component methods and properties.

Full Name in eslint-plugin-react-x

react-x/no-unused-class-component-members

Full Name in @eslint-react/eslint-plugin

@eslint-react/no-unused-class-component-members

Presets

strict strict-typescript strict-type-checked

Rule Details

This rule warns about class component methods and properties that are defined but never used. Removing unused members helps keep the codebase clean and reduces confusion.

Note that shouldComponentUpdate is considered unused when defined in a class extending PureComponent, since PureComponent implements its own shouldComponentUpdate with shallow prop and state comparison.

Examples

Class component methods defined but never used

Defining a method in a class component that is never called (including in lifecycles, render, or other methods) increases maintenance overhead and causes confusion.

// Problem: handleClick is never called
import React from "react";

class MyComponent extends React.Component {
  handleClick() {} // Unused
  render() {
    return null;
  }
}

Class component members called by other methods or lifecycles

If a method is explicitly called in a lifecycle (such as componentDidMount) or by other members, it is not considered unused.

// OK: action is called in componentDidMount
import React from "react";

class MyComponent extends React.Component {
  static getDerivedStateFromError(error: React.ErrorInfo) {
    return { hasError: true };
  }
  action() {}
  componentDidMount() {
    this.action();
  }
  render() {
    return null;
  }
}

Versions

Resources

Further Reading

On this page