oxc-project/oxc · error · OxcDiagnostic

Using string literals in ref attributes is deprecated.

Error message

Using string literals in ref attributes is deprecated.

What it means

Raised by react/no_string_refs when a JSX `ref` attribute (or equivalent) is given a string literal, e.g. `ref="myInput"`. At the throw site string refs are the deprecated pre-16 pattern; they no longer function, break with composition/HOCs, and prevent TypeScript from typing the ref. string_in_ref_deprecated fires from run() for every ref attribute whose value is a string literal, suggesting callback or object (useRef) refs instead.

Source

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

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!(
    /// ### What it does
    ///
    /// This rule prevents using the deprecated behavior of string literals in ref attributes.
    ///
    /// ### Why is this bad?
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Use ref={this.myRef} with React.createRef() in class components.
  2. Use the useRef hook in function components.
Defensive patterns

Strategy: validation

When it happens

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