DocumentationRulesno-component-will-mount

no-component-will-mount

Full Name in eslint-plugin-react-x

react-x/no-component-will-mount

Full Name in @eslint-react/eslint-plugin

@eslint-react/no-component-will-mount

Features

🔍 🔄

Presets

  • core
  • recommended
  • recommended-typescript
  • recommended-type-checked

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 to automatically update your components.

Examples

Failing

import React from "react";
 
interface ExampleProps {
  name: string;
}
 
class Example extends React.Component<ExampleProps> {
  componentWillMount() {
    // ...
  }
}

Passing

import React from "react";
 
interface ExampleProps {
  name: string;
}
 
class Example extends React.Component<ExampleProps> {
  UNSAFE_componentWillMount() {
    // ...
  }
}

Further reading