Rules
react/no-component-will-mount

react/no-component-will-mount

Rule category

Correctness.

What it does

Prevents usage of componentWillMount in class components.

Why is this bad?

This API has been renamed from componentWillMount to UNSAFE_componentWillMount. 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 (opens in a new tab) to automatically update your components.

Examples

❌ Incorrect

import React from "react";
 
class MyComponent extends React.Component {
  componentWillMount() {
    // ...
  }
}

✅ Correct

import React from "react";
 
class MyComponent extends React.Component {
  UNSAFE_componentWillMount() {
    // ...
  }
}

Further Reading