oxc-project/oxc · error · OxcDiagnostic
React hook {hook_name} depends on `{dep_name}`, which change
Error message
React hook {hook_name} depends on `{dep_name}`, which changes every render What it means
Raised by react/exhaustive-deps when a dependency is an object/array/function recreated on every render (e.g. an inline object literal or unmemoized callback). The hook re-runs every render, defeating memoization.
Source
Thrown at crates/oxc_linter/src/rules/react/exhaustive_deps.rs:174
.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"),
dep_decl_span.label(format!("`{dep_name}` is declared here")),
])
.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}."
))View on GitHub (pinned to e1e7af627c)
Solutions
- Wrap the value in useMemo or useCallback so its identity is stable.
- Store mutable values in a ref and read ref.current inside the hook.
- Move the declaration outside the component if it is constant.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/react/exhaustive_deps.rs:174 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/c3507d07cd8667c4.
Report an issue: GitHub.