oxc-project/oxc · error · OxcDiagnostic
Stateless functional components should not use `this`
Error message
Stateless functional components should not use `this`
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/react/no_this_in_sfc.rs:14
use oxc_ast::{AstKind, ast::BindingPattern};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use crate::{
AstNode,
context::LintContext,
rule::Rule,
utils::{is_es5_component, is_es6_component, is_react_component_name},
};
fn no_this_in_sfc_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Stateless functional components should not use `this`")
.with_help("Use props and context directly as function parameters instead of accessing them through `this`")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoThisInSfc;
declare_oxc_lint!(
/// ### What it does
///
/// Prevents using `this` in stateless functional components.
///
/// ### Why is this bad?
///
/// In React, stateless functional components (SFCs) receive props and context as function parameters,
/// not through `this`. Using `this` in an SFC typically indicates a mistake when converting from
/// class components or unfamiliarity with the two component styles.
///View on GitHub (pinned to e1e7af627c)
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/react/no_this_in_sfc.rs:14 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/ec17e20563ec0aa2.
Report an issue: GitHub.