oxc-project/oxc · error · OxcDiagnostic

React Hook {hook_name} was passed a dependency list that is

Error message

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.

What it means

Error "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." thrown in oxc-project/oxc.

Source

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

            ". 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.")
    .with_error_code_scope(SCOPE)
}

fn literal_in_dependency_array_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("The literal is not a valid dependency because it never changes.")
        .with_label(span)
        .with_help("Remove the literal from the array.")
        .with_error_code_scope(SCOPE)
}

fn duplicate_dependency_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("This dependency is specified more than once in the dependency array.")
        .with_label(span)
        .with_help("Remove the duplicate dependency from the array.")

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Pass a static array literal as the second argument to the hook, e.g. useEffect(fn, [dep1, dep2]).
  2. If deps must be computed dynamically, spread a memoized stable array instead of a variable reference.
Defensive patterns

Strategy: validation

When it happens

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