no-unsafe-component-will-update
Rule category
Suspicious.
What it does
Warns usage of UNSAFE_componentWillUpdate
in class components.
Why is this bad?
Using unsafe lifecycle methods like UNSAFE_componentWillUpdate
makes your component’s behavior less predictable and are more likely to cause bugs.
Examples
Failing
import React from "react";
class class Example
Example extends React.class React.Component<P = {}, S = {}, SS = any>
Component {
// @warn: Do not use 'UNSAFE_componentWillUpdate'
Example.UNSAFE_componentWillUpdate(): void
Called immediately before rendering when new props or state is received. Not called for the initial render.
Note: You cannot call
{@link
Component.setState
}
here.
This method will not stop working in React 17.
Note: the presence of
{@link
NewLifecycle.getSnapshotBeforeUpdate
getSnapshotBeforeUpdate
}
or
{@link
StaticLifecycle.getDerivedStateFromProps
getDerivedStateFromProps
}
prevents
this from being invoked.UNSAFE_componentWillUpdate() {
// ...
}
}