oxc-project/oxc · error · OxcDiagnostic

React Hook {hook_name} has a complex expression in the depen

Error message

React Hook {hook_name} has a complex expression in the dependency array.

What it means

Raised by react/exhaustive-deps when the dependency array contains a complex expression (function call, computed member access, chained logic) rather than a simple identifier. The linter cannot statically analyze its reactivity.

Source

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

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

fn complex_expression_in_dependency_array_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "React Hook {hook_name} has a complex expression in the dependency array.",
    ))
    .with_label(span)
    .with_help("Extract the expression to a separate variable so it can be statically checked.")
    .with_error_code_scope(SCOPE)
}

fn dependency_changes_on_every_render_diagnostic(
    hook_name: &str,
    span: Span,
    dep_name: &str,
    dep_decl_span: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "React hook {hook_name} depends on `{dep_name}`, which changes every render"
    ))
    .with_labels([
        span.primary_label("it will always cause this hook to re-evaluate"),

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Extract the expression into a variable (often memoized with useMemo) and depend on that variable.
  2. Simplify the expression to a plain identifier or property access.
Defensive patterns

Strategy: validation

When it happens

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