{"record":{"id":"8b673652a1e84e03","repo":"oxc-project/oxc","slug":"components-should-use-an-es2015-class-instead-of","errorCode":null,"errorMessage":"Components should use an ES2015 class instead of `createReactClass`.","messagePattern":"Components should use an ES2015 class instead of `createReactClass`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/prefer_es6_class.rs","lineNumber":20,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::{DefaultRuleConfig, Rule},\n    utils::{AlwaysNever, is_es5_component, is_es6_component},\n};\n\nfn unexpected_es6_class_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Components should use `createReactClass` instead of an ES2015 class.\")\n        .with_label(span)\n}\n\nfn expected_es6_class_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Components should use an ES2015 class instead of `createReactClass`.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct PreferEs6Class(AlwaysNever);\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// React offers you two ways to create traditional components: using the\n    /// `create-react-class` package or the newer ES2015 class system.\n    ///\n    /// Note that function components are preferred over class components in modern React,\n    /// and it is _especially_ discouraged to use `createReactClass` in modern React.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// This rule enforces a consistent React class style.","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/prefer_es6_class.rs#L2-L38","documentation":"Raised by react/prefer_es6_class when configured with `always` and a component is written as an ES2015 class while the project mandates `createReactClass`. At the throw site the class form conflicts with the enforced factory style — typically adopted to use the autobinding/mixins behavior of createReactClass. expected_es6_class_diagnostic fires from run() when is_es6_component matches a class declaration/expression representing a component and the config selects the createReactClass-preferred mode.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/prefer_es6_class.rs:20 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rewrite the component as an ES2015 class extending React.Component.","Convert it to a function component if lifecycle features are unused."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}