{"record":{"id":"3ffee853708a1317","repo":"oxc-project/oxc","slug":"react-hook-hook-name-contains-a-call-to-setstate","errorCode":null,"errorMessage":"React Hook {hook_name} contains a call to setState. Without a list of dependencies, this can lead to an infinite chain of updates.","messagePattern":"React Hook (.+?) contains a call to setState\\. Without a list of dependencies, this can lead to an infinite chain of updates\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/exhaustive_deps.rs","lineNumber":194,"sourceCode":"    .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.\")\n        .with_label(span)\n        .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.\")\n        .with_error_code_scope(SCOPE)\n}\n\nfn functions_returned_from_use_effect_event_must_not_be_included_in_dependency_array(\n    span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/oxc-project/oxc/blob/1f902a69625cd14e6d8dc58feca94da099d2d251/crates/oxc_linter/src/rules/react/exhaustive_deps.rs#L176-L212","documentation":"Raised by react/exhaustive_deps when a hook is called with no dependency array and its callback contains a call to a setState (or dispatch) function. At the throw site the state update triggers a re-render, which re-runs the dependency-less effect, which calls setState again — an infinite update loop. run() reports this when the unconditional-deps mode detects a setter invocation inside the hook body while the deps argument is absent.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/exhaustive_deps.rs:199 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add a dependency array (even []) so the effect runs only when intended.","Guard the setState call so it does not fire unconditionally on every run."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1f902a69625cd14e6d8dc58feca94da099d2d251","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}