{"record":{"id":"b9ee29a8e545326f","repo":"oxc-project/oxc","slug":"using-string-literals-in-ref-attributes-is-depreca","errorCode":null,"errorMessage":"Using string literals in ref attributes is deprecated.","messagePattern":"Using string literals in ref attributes is deprecated\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/no_string_refs.rs","lineNumber":28,"sourceCode":"use oxc_span::{GetSpan, Span};\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::{DefaultRuleConfig, Rule},\n    utils::get_parent_component,\n};\n\nfn this_refs_deprecated(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Using this.refs is deprecated.\")\n        .with_help(\"Using this.xxx instead of this.refs.xxx\")\n        .with_label(span)\n}\n\nfn string_in_ref_deprecated(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Using string literals in ref attributes is deprecated.\")\n        .with_help(\"Using reference callback instead\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoStringRefs {\n    /// Disallow template literals in addition to string literals.\n    no_template_literals: bool,\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule prevents using the deprecated behavior of string literals in ref attributes.\n    ///\n    /// ### Why is this bad?\n    ///","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/no_string_refs.rs#L10-L46","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/no_string_refs.rs:28 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use ref={this.myRef} with React.createRef() in class components.","Use the useRef hook in function components."],"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"}