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 Example
Example extends React.class React.Component<P = {}, S = {}, SS = any>
Component {
Example.handleClick(): void
handleClick() {} // Unused
Example.render(): null
render() {
return null;
}
}
Passing
import React from "react";
class class Example
Example extends React.class React.Component<P = {}, S = {}, SS = any>
Component {
static Example.getDerivedStateFromError(error: React.ErrorInfo): {
hasError: boolean;
}
getDerivedStateFromError(error: React.ErrorInfo
error: React.interface React.ErrorInfo
ErrorInfo) {
return { hasError: boolean
hasError: true };
}
Example.action(): void
action() {}
Example.componentDidMount(): void
Called immediately after a component is mounted. Setting state here will trigger re-rendering.componentDidMount() {
this.Example.action(): void
action();
}
Example.render(): null
render() {
return null;
}
}