Rules
react-avoid-class-components

Don’t use React class components

React class components are deprecated. Use React functions and hooks instead.

Note that uses classes is fine for non-react components.

Examples

Incorrect Examples

import { Component } from 'react'
 
export class Label extends Component {
  render() {
    return <div>Hello</div>
  }
}
import react from 'react'
 
export class Label extends react.Component {
  render() {
    return <div />
  }
}

Correct Examples

export function Button() {
  return <div>Hello</div>
}
import EventEmitter from 'eventemitter3'
 
// This is fine because it is a normal class and not a React component.
class Foo extends EventEmitter {
  constructor() {}
}

Metadata

KeyValue
namereact-avoid-class-components
levelerror
scopefile
fixablefalse
cacheabletrue
tags[ react ]
eslint[ eslint-plugin-react-prefer-function-component ]
include[ **/*.{jsx,tsx} ]
gritqltrue