{"record":{"id":"ec17e20563ec0aa2","repo":"oxc-project/oxc","slug":"stateless-functional-components-should-not-use-th","errorCode":null,"errorMessage":"Stateless functional components should not use `this`","messagePattern":"Stateless functional components should not use `this`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/no_this_in_sfc.rs","lineNumber":14,"sourceCode":"use oxc_ast::{AstKind, ast::BindingPattern};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::Rule,\n    utils::{is_es5_component, is_es6_component, is_react_component_name},\n};\n\nfn no_this_in_sfc_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Stateless functional components should not use `this`\")\n        .with_help(\"Use props and context directly as function parameters instead of accessing them through `this`\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoThisInSfc;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prevents using `this` in stateless functional components.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// In React, stateless functional components (SFCs) receive props and context as function parameters,\n    /// not through `this`. Using `this` in an SFC typically indicates a mistake when converting from\n    /// class components or unfamiliarity with the two component styles.\n    ///","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/no_this_in_sfc.rs#L1-L32","documentation":"Raised by react/no_this_in_sfc when `this` is referenced inside a stateless functional component (a function component detected by the react component-name/component-shape heuristics). At the throw site function components have no instance: `this` is undefined in strict mode, so any `this.props`/`this.state` access is a bug or leftover from converting a class component. run() flags ThisExpression nodes enclosed by function components, telling authors to use props/context parameters instead.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/no_this_in_sfc.rs:14 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use the component's props parameter directly instead of this.props.","Accept context as a parameter or use a hook instead of this.context."],"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-14T00:17:10.932Z"}