Skip to main content
ESLint Interlace
Plugin: react-featuresRules

no-unsafe

Warn about UNSAFE_ lifecycle methods. This rule is part of eslint-plugin-react-features and provides LLM-optimized error messages.

Keywords: React, UNSAFE, lifecycle, deprecated, ESLint rule, code quality, LLM-optimized

Warn about UNSAFE_ lifecycle methods. This rule is part of eslint-plugin-react-features and provides LLM-optimized error messages.

Quick Summary

AspectDetails
SeverityWarning (code quality)
Auto-Fix❌ No auto-fix
CategoryReact
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForAll React/JSX projects

Rule Details

UNSAFE_ lifecycle methods may cause issues with async rendering and will be removed in future React versions.

Examples

❌ Incorrect

class MyComponent extends React.Component {
  UNSAFE_componentWillMount() {
    this.loadData();
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    this.updateState(nextProps);
  }

  UNSAFE_componentWillUpdate(nextProps, nextState) {
    this.prepareUpdate();
  }
}

✅ Correct

class MyComponent extends React.Component {
  componentDidMount() {
    this.loadData();
  }

  static getDerivedStateFromProps(props, state) {
    return { derivedValue: props.value };
  }

  getSnapshotBeforeUpdate(prevProps, prevState) {
    return this.divRef.scrollHeight;
  }
}