no-component-will-update
Rule category
Restriction.
What it does
Prevents usage of componentWillUpdate
in class components.
Why is this bad?
This API has been renamed from componentWillUpdate
to UNSAFE_componentWillUpdate
. The old name has been deprecated. In a future major version of React, only the new name will work.
Run the rename-unsafe-lifecycles codemod to automatically update your components.
Examples
Failing
import React from "react";
class class ExampleComponent
ExampleComponent extends React.class React.Component<P = {}, S = {}, SS = any>
Component {
ExampleComponent.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.
Note: the presence of
{@link
NewLifecycle.getSnapshotBeforeUpdate
getSnapshotBeforeUpdate
}
or
{@link
StaticLifecycle.getDerivedStateFromProps
getDerivedStateFromProps
}
prevents
this from being invoked.componentWillUpdate() {
// ...
}
}
Passing
import React from "react";
class class ExampleComponent
ExampleComponent extends React.class React.Component<P = {}, S = {}, SS = any>
Component {
ExampleComponent.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() {
// ...
}
}