oxc-project/oxc · error · OxcDiagnostic

Using this.refs is deprecated.

Error message

Using this.refs is deprecated.

What it means

Raised by react/no_string_refs when code accesses `this.refs` (a member expression on `refs` of `this`). At the throw site the component uses the legacy refs API removed in React 16 — `this.refs` only returns the DOM node, not the component, and no longer works — so the code is broken or relying on ancient behavior. run() reports member accesses on this.refs via this_refs_deprecated.

Source

Thrown at crates/oxc_linter/src/rules/react/no_string_refs.rs:22

        Expression, JSXAttribute, JSXAttributeName, JSXAttributeValue, JSXExpression,
        JSXExpressionContainer,
    },
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use schemars::JsonSchema;
use serde::Deserialize;

use crate::{
    AstNode,
    context::{ContextHost, LintContext},
    rule::{DefaultRuleConfig, Rule},
    utils::get_parent_component,
};

fn this_refs_deprecated(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Using this.refs is deprecated.")
        .with_help("Using this.xxx instead of this.refs.xxx")
        .with_label(span)
}

fn string_in_ref_deprecated(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Using string literals in ref attributes is deprecated.")
        .with_help("Using reference callback instead")
        .with_label(span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoStringRefs {
    /// Disallow template literals in addition to string literals.
    no_template_literals: bool,
}

declare_oxc_lint!(

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Use React.createRef() or callback refs instead of this.refs.
  2. Access members directly rather than through this.refs.xxx.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/react/no_string_refs.rs:22 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/b864a31114dfcd20. Report an issue: GitHub.