oxc-project/oxc · error · OxcDiagnostic

react-hooks

react-hooks

Error message

Functions returned from `useEffectEvent` must not be included in the dependency array.

What it means

Raised by react/exhaustive_deps when a function returned from useEffectEvent is listed in a hook's dependency array. At the throw site the whole point of useEffectEvent is that its returned function is guaranteed stable and must never be a dependency — including it is both unnecessary and explicitly unsupported by React's contract, and can defeat the event function's ability to read latest props/state. run() matches dependency-array identifiers against useEffectEvent declarations and reports the offending entry.

Source

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

    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(
        "Functions returned from `useEffectEvent` must not be included in the dependency array.",
    )
    .with_label(span)
    .with_help("Remove the dependency from the dependency array.")
    .with_error_code_scope(SCOPE)
}

#[derive(Debug, Default, Clone, Deserialize)]
pub struct ExhaustiveDeps(Box<ExhaustiveDepsConfig>);

#[derive(Debug, Clone, Default, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
struct ExhaustiveDepsConfig {
    /// Optionally provide a regex of additional hooks to check.
    #[serde(default, deserialize_with = "deserialize_additional_hooks")]
    additional_hooks: Option<Regex>,
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the useEffectEvent-returned function from the dependency array; call it directly inside the hook body.
Defensive patterns

Strategy: validation

When it happens

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