Skip to content

react/no-is-mounted Correctness ​

✅ This rule is turned on by default.

What it does ​

This rule prevents using isMounted in ES6 classes

Why is this bad? ​

isMounted is an anti-pattern, is not available when using ES6 classes, and it is on its way to being officially deprecated.///

Example ​

jsx
class Hello extends React.Component {
  someMethod() {
    if (!this.isMounted()) {
      return;
    }
  }
  render() {
    return <div onClick={this.someMethod.bind(this)}>Hello</div>;
  }
}

How to use ​

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny react/no-is-mounted
json
{
  "rules": {
    "react/no-is-mounted": "error"
  }
}

References ​

Released under the MIT License.