Try @eslint-react/kit@beta
logoESLint React

no-unsafe-component-will-update

Warns about the use of 'UNSAFE_componentWillUpdate' in class components.

Full Name in eslint-plugin-react-x

react-x/no-unsafe-component-will-update

Full Name in @eslint-react/eslint-plugin

@eslint-react/no-unsafe-component-will-update

Presets

x recommended recommended-typescript recommended-type-checked strict strict-typescript strict-type-checked

Rule Details

Using unsafe lifecycle methods like UNSAFE_componentWillUpdate makes your component's behavior less predictable and is more likely to cause bugs. Consider using componentDidUpdate instead.

Examples

Using UNSAFE_componentWillUpdate in class components

UNSAFE_componentWillUpdate is a deprecated lifecycle method. If you need to perform side effects or DOM operations after an update, use componentDidUpdate.

// Problem: Uses an unsafe lifecycle method
import React from "react";

class MyComponent extends React.Component {
  UNSAFE_componentWillUpdate() {
    // ...
  }
}
// Recommended: use componentDidUpdate for side effects after an update
import React from "react";

class MyComponent extends React.Component {
  componentDidUpdate(prevProps, prevState) {
    if (this.props.value !== prevProps.value) {
      // Perform side effects here
    }
  }
}

Versions

Resources

Further Reading


See Also

On this page