Skip to main content
interlace
Plugin: react-featuresRules

no-is-mounted

no-is-mounted rule

no-is-mounted rule

Prevent using isMounted() in React class components. This rule is part of eslint-plugin-react-features.

Quick Summary

AspectDetails
SeverityError (deprecated)
Auto-Fix❌ No (requires refactoring)
CategoryReact
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForAll React class components

Rule Details

isMounted() is deprecated and indicates an anti-pattern. Cancel async operations properly instead.

Why This Matters

IssueImpactSolution
⚠️ DeprecatedRemoved from ReactCancel in unmount
🐛 Anti-patternHides real issuesProper cleanup
💾 Memory leaksOperations not cancelledAbortController

Examples

❌ Incorrect

class MyComponent extends React.Component {
  async fetchData() {
    const data = await api.fetch();
    if (this.isMounted()) {  // Deprecated!
      this.setState({ data });
    }
  }
}

✅ Correct

// Class component with proper cleanup
class MyComponent extends React.Component {
  abortController = new AbortController();
  
  componentWillUnmount() {
    this.abortController.abort();
  }
  
  async fetchData() {
    try {
      const data = await api.fetch({ signal: this.abortController.signal });
      this.setState({ data });
    } catch (e) {
      if (e.name === 'AbortError') return;
      throw e;
    }
  }
}

// Function component (recommended)
function MyComponent() {
  const [data, setData] = useState(null);
  
  useEffect(() => {
    const controller = new AbortController();
    
    api.fetch({ signal: controller.signal })
      .then(setData)
      .catch(e => e.name !== 'AbortError' && console.error(e));
    
    return () => controller.abort();
  }, []);
}

Configuration Examples

Basic Usage

{
  rules: {
    'react-features/no-is-mounted': 'error'
  }
}

Further Reading

Known False Negatives

  • An alias of this (const self = this; self.isMounted()) is not read as the component's method.
  • createReactClass components are not covered; only classes that extend React's Component / PureComponent.

Not reported by design: a flag or variable the code names isMounted (this.isMounted = true, const isMounted = useRef(false)), which is the replacement pattern, not the deprecated API.

Use this rule

npm install -D oxlint-plugin-react-features
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-react-features"],  "rules": {    "react-features/no-is-mounted": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-react-features'],    rules: {      'react-features/no-is-mounted': 'error',    },  },});

oxlint-plugin-react-features re-exports eslint-plugin-react-features/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.