oxc-project/oxc · error · OxcDiagnostic
useState call is not destructured into value + setter pair
Error message
useState call is not destructured into value + setter pair
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/react/hook_use_state.rs:15
use crate::{
AstNode,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
utils::is_react_function_call,
};
use oxc_ast::{AstKind, ast::BindingPattern};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
fn require_to_destruct(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("useState call is not destructured into value + setter pair")
.with_help(
"Destructure useState call into value + setter pair \
follow the [thing, setThing] naming convention",
)
.with_label(span)
}
fn follow_naming_convention(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("useState call does not follow the [thing, setThing] naming convention")
.with_help("Follow the [thing, setThing] naming convention")
.with_label(span)
}
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
struct HookUseStateConfig {
/// When true the rule will ignore the name of the destructured value.
allow_destructured_state: bool,View on GitHub (pinned to e1e7af627c)
Solutions
- Destructure the return value: const [count, setCount] = useState(0).
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/react/hook_use_state.rs:15 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/b82f74698ef1c13a.
Report an issue: GitHub.