oxc-project/oxc · error · OxcDiagnostic

React Hook {hook_name} contains a call to setState. Without

Error message

React Hook {hook_name} contains a call to setState. Without a list of dependencies, this can lead to an infinite chain of updates.

What it means

Raised by react/exhaustive_deps when a hook is called with no dependency array and its callback contains a call to a setState (or dispatch) function. At the throw site the state update triggers a re-render, which re-runs the dependency-less effect, which calls setState again — an infinite update loop. run() reports this when the unconditional-deps mode detects a setter invocation inside the hook body while the deps argument is absent.

Source

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

    .with_help("Try memoizing this variable with `useRef` or `useCallback`.")
    .with_error_code_scope(SCOPE)
}

fn unnecessary_outer_scope_dependency_diagnostic(
    hook_name: &str,
    dep_name: &str,
    span: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "React Hook {hook_name} has an unnecessary dependency: {dep_name}."
    ))
    .with_label(span)
    .with_help("Consider removing it from the dependency array. Outer scope values aren't valid dependencies because mutating them doesn't re-render the component.")
    .with_error_code_scope(SCOPE)
}

fn infinite_rerender_call_to_set_state_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "React Hook {hook_name} contains a call to setState. Without a list of dependencies, this can lead to an infinite chain of updates."
    ))
    .with_label(span)
    .with_help("Consider adding an empty list of dependencies to make it clear which values are intended to be stable.")
    .with_error_code_scope(SCOPE)
}

fn ref_accessed_directly_in_effect_cleanup_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("The ref's value `.current` is accessed directly in the effect cleanup function.")
        .with_label(span)
        .with_help("The ref value will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by react, copy it to a variable inside the effect and use that variable in the cleanup function.")
        .with_error_code_scope(SCOPE)
}

fn functions_returned_from_use_effect_event_must_not_be_included_in_dependency_array(
    span: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add a dependency array (even []) so the effect runs only when intended.
  2. Guard the setState call so it does not fire unconditionally on every run.
Defensive patterns

Strategy: validation

When it happens

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