oxc-project/oxc · error · OxcDiagnostic

React Hook {hook_name} has missing dependencies: {deps_prett

Error message

React Hook {hook_name} has missing dependencies: {deps_pretty}

What it means

Raised by react/exhaustive_deps when values referenced inside the effect callback are not listed in the hook's dependency array. At the throw site the effect closes over reactive values (props, state, or other values that can change between renders) that are absent from the deps list, so the callback would operate on stale data. The message lists the missing dependency names (singular vs plural form) and optionally appends a note when the missing value is a mutable ref. run() computes the actual referenced values vs the declared array and reports the difference.

Source

Thrown at crates/oxc_linter/src/rules/react/exhaustive_deps.rs:123

                dep.span.into()
            }
        })
        .chain(std::iter::once(span.primary()));

    let mut message = if single {
        format!("React Hook {hook_name} has a missing dependency: {deps_pretty}")
    } else {
        format!("React Hook {hook_name} has missing dependencies: {deps_pretty}")
    };

    if let Some(dep) = mutable_ref_dependency {
        let _ = write!(
            message,
            ". Mutable values like '{dep}' aren't valid dependencies because mutating them doesn't re-render the component."
        );
    }

    OxcDiagnostic::warn(message)
        .with_labels(labels)
        .with_help("Either include it or remove the dependency array.")
        .with_error_code_scope(SCOPE)
}

fn unnecessary_dependency_diagnostic(hook_name: &str, dep_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("React Hook {hook_name} has unnecessary dependency: {dep_name}"))
        .with_label(span)
        .with_help("Either include it or remove the dependency array.")
        .with_error_code_scope(SCOPE)
}

fn dependency_array_not_array_literal_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "React Hook {hook_name} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies."
    ))
    .with_label(span)
    .with_help("Use an array literal as the second argument.")

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add all listed values to the dependency array.
  2. Refactor values that should stay stable into refs or memoized callbacks.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/react/exhaustive_deps.rs:123 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/8080eb51ce5d8d6c. Report an issue: GitHub.