oxc-project/oxc · error · OxcDiagnostic

Components should use `createReactClass` instead of an ES201

Error message

Components should use `createReactClass` instead of an ES2015 class.

What it means

Raised by react/prefer_es6_class when configured with `never` and a component is defined via `React.createClass`/`createReactClass` instead of an ES2015 class. At the throw site the legacy factory API is deprecated (removed from React core) and the project mandates class components; unexpected_es6_class_diagnostic fires from run() when a createReactClass call is detected that constitutes a component definition, telling authors to convert it to `class X extends React.Component`.

Source

Thrown at crates/oxc_linter/src/rules/react/prefer_es6_class.rs:15

use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use serde::Deserialize;

use crate::{
    AstNode,
    context::{ContextHost, LintContext},
    rule::{DefaultRuleConfig, Rule},
    utils::{AlwaysNever, is_es5_component, is_es6_component},
};

fn unexpected_es6_class_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Components should use `createReactClass` instead of an ES2015 class.")
        .with_label(span)
}

fn expected_es6_class_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Components should use an ES2015 class instead of `createReactClass`.")
        .with_label(span)
}

#[derive(Debug, Default, Clone, Deserialize)]
pub struct PreferEs6Class(AlwaysNever);

declare_oxc_lint!(
    /// ### What it does
    ///
    /// React offers you two ways to create traditional components: using the
    /// `create-react-class` package or the newer ES2015 class system.
    ///
    /// Note that function components are preferred over class components in modern React,

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Convert the class component to createReactClass if the legacy pattern is required by the codebase.
  2. Change the rule option to 'never' to enforce ES classes instead.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/react/prefer_es6_class.rs:15 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/b555b0fe76a2ebd2. Report an issue: GitHub.