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-membersFull Name in @eslint-react/eslint-plugin
@eslint-react/no-unused-class-component-membersPresets
x
recommended
recommended-typescript
recommended-type-checked
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.
Public methods (including function-valued properties) of an exported class component are not reported, as they may be part of the component's imperative API invoked by consumers through refs (e.g. drawerRef.current.openDrawer()). Data fields, private/protected members, and members of non-exported classes are still reported.
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: Error) {
return { hasError: true };
}
action() {}
componentDidMount() {
this.action();
}
render() {
return null;
}
}