Rules
no-component-will-receive-props

no-component-will-receive-props

Rule category

Restriction.

What it does

Prevents usage of componentWillReceiveProps in class components.

Why is this bad?

This API has been renamed from componentWillReceiveProps to UNSAFE_componentWillReceiveProps. 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 ExampleExample extends React.class React.Component<P = {}, S = {}, SS = any>Component {
  Example.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. 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; will stop working in React 17@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}
componentWillReceiveProps
() {
// ... } }

Passing

import React from "react";
 
class class ExampleExample extends React.class React.Component<P = {}, S = {}, SS = any>Component {
  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
() {
// ... } }

Further Reading