Rules
no-unsafe-component-will-receive-props

no-unsafe-component-will-receive-props

Rule category

Suspicious.

What it does

Warns usage of UNSAFE_componentWillReceiveProps in class components.

Why is this bad?

Using unsafe lifecycle methods like UNSAFE_componentWillReceiveProps makes your component’s behavior less predictable and are more likely to cause bugs.

Examples

Failing

import React from "react";
 
class class ExampleExample extends React.class React.Component<P = {}, S = {}, SS = any>Component {
  // @warn: Do not use 'UNSAFE_componentWillReceiveProps'
  Example.UNSAFE_componentWillReceiveProps(): void
Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes. Calling {@link Component.setState } generally does not trigger this method. 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.
@deprecated16.3, use static {@link StaticLifecycle.getDerivedStateFromPropsgetDerivedStateFromProps} instead@see{@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props}@see{@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
UNSAFE_componentWillReceiveProps
() {
// ... } }