Rules
no-unused-class-component-members

no-unused-class-component-members

Rule category

Correctness.

What it does

Warns unused class component methods and properties.

Examples

Failing

import React from "react";
 
class class ExampleExample extends React.class React.Component<P = {}, S = {}, SS = any>Component {
  Example.handleClick(): voidhandleClick() {} // Unused
  Example.render(): nullrender() {
    return null;
  }
}

Passing

import React from "react";
 
class class ExampleExample extends React.class React.Component<P = {}, S = {}, SS = any>Component {
  static Example.getDerivedStateFromError(error: React.ErrorInfo): {
hasError: boolean;
}
getDerivedStateFromError
(error: React.ErrorInfoerror: React.interface React.ErrorInfoErrorInfo) {
return { hasError: booleanhasError: true }; } Example.action(): voidaction() {} Example.componentDidMount(): void
Called immediately after a component is mounted. Setting state here will trigger re-rendering.
componentDidMount
() {
this.Example.action(): voidaction(); } Example.render(): nullrender() { return null; } }