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-updateFull Name in @eslint-react/eslint-plugin
@eslint-react/no-unsafe-component-will-updatePresets
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
- React Docs:
UNSAFE_componentWillUpdate - Legacy React APIs:
componentWillUpdate - React Docs: Updating to Async Rendering
- React Docs: How to migrate to a function component
See Also
react-x/no-unsafe-component-will-mount
Warns about the use ofUNSAFE_componentWillMountin class components.react-x/no-unsafe-component-will-receive-props
Warns about the use ofUNSAFE_componentWillReceivePropsin class components.