{"record":{"id":"b82f74698ef1c13a","repo":"oxc-project/oxc","slug":"usestate-call-is-not-destructured-into-value-set","errorCode":null,"errorMessage":"useState call is not destructured into value + setter pair","messagePattern":"useState call is not destructured into value \\+ setter pair","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/hook_use_state.rs","lineNumber":15,"sourceCode":"use crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::is_react_function_call,\n};\nuse oxc_ast::{AstKind, ast::BindingPattern};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nfn require_to_destruct(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"useState call is not destructured into value + setter pair\")\n        .with_help(\n            \"Destructure useState call into value + setter pair \\\n            follow the [thing, setThing] naming convention\",\n        )\n        .with_label(span)\n}\n\nfn follow_naming_convention(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"useState call does not follow the [thing, setThing] naming convention\")\n        .with_help(\"Follow the [thing, setThing] naming convention\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\nstruct HookUseStateConfig {\n    /// When true the rule will ignore the name of the destructured value.\n    allow_destructured_state: bool,","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/hook_use_state.rs#L1-L33","documentation":"Raised by react/hook_use_state when a useState call's return value is not destructured into an array pair, e.g. `const state = useState(0)` or the result is discarded. At the throw site the state value and its setter cannot be accessed independently — reading `state` gives the whole tuple — so the code either does not work as intended or violates the enforced idiom. require_to_destruct fires from run() whenever the declarator's binding pattern is not an array destructuring of exactly the hook call.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/hook_use_state.rs:15 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Destructure the return value: const [count, setCount] = useState(0)."],"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"}