oxc-project/oxc · error · OxcDiagnostic

React hook {hook_name} requires an effect callback.

Error message

React hook {hook_name} requires an effect callback.

What it means

Raised by react/exhaustive_deps (react-hooks scope) when an effect-style hook such as useEffect or useLayoutEffect is invoked without a callback function as its first argument (e.g. useEffect()). At the throw site the hook call is a no-op: the hook registration is malformed and nothing is scheduled to run after render. run() checks each detected React hook call expression and reports this when the first argument is missing or is not a function.

Source

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

use oxc_span::{GetSpan, Span};
use oxc_str::Str;
use oxc_syntax::scope::ScopeFlags;

use crate::{
    AstNode,
    ast_util::variable_declaration_kind,
    ast_util::{
        get_declaration_from_reference_id, get_declaration_of_variable, get_enclosing_function,
    },
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
    utils::deserialize_regex_option,
};

const SCOPE: &str = "react-hooks";

fn missing_callback_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("React hook {hook_name} requires an effect callback."))
        .with_label(span)
        .with_help("Did you forget to pass a callback to the hook?")
        .with_error_code_scope(SCOPE)
}

fn dependency_array_required_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "React Hook {hook_name} does nothing when called with only one argument."
    ))
    .with_label(span)
    .with_help("Did you forget to pass an array of dependencies?")
    .with_error_code_scope(SCOPE)
}

fn unknown_dependencies_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "React Hook {hook_name} received a function whose dependencies are unknown."
    ))

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Pass a callback function as the first argument to the hook, e.g. useEffect(() => {...}, []).
Defensive patterns

Strategy: validation

When it happens

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