{"record":{"id":"419a21df05f0ecd4","repo":"oxc-project/oxc","slug":"react-hook-hook-name-has-an-unnecessary-dependen","errorCode":null,"errorMessage":"React Hook {hook_name} has an unnecessary dependency: {dep_name}.","messagePattern":"React Hook (.+?) has an unnecessary dependency: (.+?)\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/exhaustive_deps.rs","lineNumber":190,"sourceCode":"    dep_decl_span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"React hook {hook_name} depends on `{dep_name}`, which changes every render\"\n    ))\n    .with_labels([\n        span.primary_label(\"it will always cause this hook to re-evaluate\"),\n        dep_decl_span.label(format!(\"`{dep_name}` is declared here\")),\n    ])\n    .with_help(\"Try memoizing this variable with `useRef` or `useCallback`.\")\n    .with_error_code_scope(SCOPE)\n}\n\nfn unnecessary_outer_scope_dependency_diagnostic(\n    hook_name: &str,\n    dep_name: &str,\n    span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"React Hook {hook_name} has an unnecessary dependency: {dep_name}.\"\n    ))\n    .with_label(span)\n    .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.\")\n    .with_error_code_scope(SCOPE)\n}\n\nfn infinite_rerender_call_to_set_state_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"React Hook {hook_name} contains a call to setState. Without a list of dependencies, this can lead to an infinite chain of updates.\"\n    ))\n    .with_label(span)\n    .with_help(\"Consider adding an empty list of dependencies to make it clear which values are intended to be stable.\")\n    .with_error_code_scope(SCOPE)\n}\n\nfn ref_accessed_directly_in_effect_cleanup_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"The ref's value `.current` is accessed directly in the effect cleanup function.\")","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/exhaustive_deps.rs#L172-L208","documentation":"Raised by react/exhaustive-deps when the dependency array includes a value from an outer scope (e.g. a module-level mutable or a parent render's variable not relevant to this hook). Outer-scope values are not valid hook dependencies.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/exhaustive_deps.rs:190 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the outer-scope value from the dependency array.","Pass the value down as a prop or parameter if it genuinely needs to be reactive."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}