# react/prefer-es6-class

> Enforce one way to write class components: `class` or `createReactClass`

You can write a class component with `class` or with `createReactClass()`. The two differ in how methods are bound and how the initial state and the default props are set, so a codebase that mixes them is harder to read. By default, the rule requires `class`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"react/prefer-es6-class" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"react/prefer-es6-class" = ["error", "always"] # "always" or "never"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```jsx
const Greeting = createReactClass({
  render() {
    return <h1>Hello {this.props.name}</h1>;
  },
});
```

Not reported:

{/* good */}
```jsx
class Greeting extends React.Component {
  render() {
    return <h1>Hello {this.props.name}</h1>;
  }
}
```

## Options

| Option | What it does |
| --- | --- |
| `"always"` (default) | Report components made with `createReactClass()`. |
| `"never"` | Report components written as a `class` declaration. |

Reported with `"never"`:

{/* bad {"options": ["never"]} */}
```jsx
class Greeting extends React.Component {
  render() {
    return <h1>Hello {this.props.name}</h1>;
  }
}
```
