oxc-project/oxc · error · OxcDiagnostic

The ref's value `.current` is accessed directly in the effec

Error message

The ref's value `.current` is accessed directly in the effect cleanup function.

What it means

Raised by react/exhaustive_deps when the effect's cleanup function reads `ref.current` directly. At the throw site the cleanup captures the mutable ref object and dereferences `.current` at cleanup time; by then React has usually already set `.current` to null (for ref objects attached to DOM nodes), so the code reads a stale or null value instead of the value from when the effect ran. run() scans cleanup bodies for `.current` member accesses and reports them.

Source

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

    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(
        "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>);

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Capture ref.current in a local variable inside the effect body and use that captured value in the cleanup.
  2. Ensure the ref is only cleared after cleanup completes.
Defensive patterns

Strategy: validation

When it happens

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