oxc-project/oxc · error · OxcDiagnostic

Components wrapped with `forwardRef` must have a `ref` param

Error message

Components wrapped with `forwardRef` must have a `ref` parameter

What it means

Raised by react/forward-ref-uses-ref when a component wrapped in React.forwardRef does not declare a ref parameter in its render function. The forwarded ref is silently dropped and never reaches the DOM node.

Source

Thrown at crates/oxc_linter/src/rules/react/forward_ref_uses_ref.rs:14

use oxc_ast::{
    AstKind,
    ast::{CallExpression, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{
    AstNode, ast_util::outermost_paren_parent, context::LintContext, fixer::RuleFixer, rule::Rule,
};

fn forward_ref_uses_ref_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Components wrapped with `forwardRef` must have a `ref` parameter")
        .with_help("Add a `ref` parameter, or remove `forwardRef`")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct ForwardRefUsesRef;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Requires that components wrapped with `forwardRef` must have a `ref` parameter.
    /// Omitting the `ref` argument is usually a bug,
    /// and components not using `ref` don't need to be wrapped by `forwardRef`.
    ///
    /// ### Why is this bad?
    ///
    /// Omitting the `ref` argument makes the `forwardRef` wrapper unnecessary,
    /// and can lead to confusion.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add the ref parameter: forwardRef((props, ref) => ...) and attach it to the rendered element.
  2. Remove forwardRef if the component does not need to expose a ref.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/react/forward_ref_uses_ref.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/12f094a81b3bbc92. Report an issue: GitHub.