close

no-is-mounted

Configuration

PresetConfigured Value
✅ reactPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, reactPlugin } from '@rslint/core';

export default defineConfig([
  reactPlugin.configs.recommended,
  {
    rules: {
      'react/no-is-mounted': 'error',
    },
  },
]);

Disallow usage of isMounted.

isMounted is an anti-pattern, is not available when using ES6 classes, and is officially deprecated by the React team.

Rule Details

This rule flags calls to this.isMounted() inside properties of an object literal (e.g. a createReactClass spec) or inside methods / getters / setters / constructors of a class. Calls outside any such method are ignored.

Examples of incorrect code for this rule:

var Hello = createReactClass({
  componentDidUpdate: function () {
    if (!this.isMounted()) {
      return;
    }
  },
  render: function () {
    return <div>Hello</div>;
  },
});
class Hello extends React.Component {
  someMethod() {
    if (!this.isMounted()) {
      return;
    }
  }
  render() {
    return <div onClick={this.someMethod.bind(this)}>Hello</div>;
  }
}

Examples of correct code for this rule:

var Hello = createReactClass({
  render: function () {
    return <div>Hello</div>;
  },
});
var Hello = createReactClass({
  componentDidUpdate: function () {
    someNonMemberFunction(arg);
    this.someFunc = this.isMounted;
  },
  render: function () {
    return <div>Hello</div>;
  },
});
class Hello extends React.Component {
  notIsMounted() {}
  render() {
    this.notIsMounted();
    return <div>Hello</div>;
  }
}

Original Documentation