hook-use-state
Added in v0.9.1Configuration
Require useState calls to be destructured into a value and matching setter
pair.
Rule Details
This rule ensures that a React useState call uses a symmetric
[value, setValue] destructure. Returning a useState result directly is
allowed.
Suggestions that replace a TypeScript destructuring pattern also remove its type annotation. The annotation describes the original pattern and is not carried over to the replacement.
JavaScript JSDoc casts are transparent to this rule.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
allowDestructuredState defaults to false. When enabled, the value part may
itself be destructured, provided the setter remains a simple binding.
Examples of correct code for this rule with
{ "allowDestructuredState": true }: