react/hook-use-state
eslint-plugin-react
Suggestion
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/hook-use-state": "error",
},
},
];Ensure destructuring and symmetric naming of useState hook value and setter variables
import React from 'react';
export default function useColor() {
// useState call is not destructured into value + setter pair
const useStateResult = React.useState();
return useStateResult;
}import React from 'react';
export default function useColor() {
// useState call is destructured into value + setter pair, but identifier
// names do not follow the [thing, setThing] naming convention
const [color, updateColor] = React.useState();
return [color, updateColor];
}import React from 'react';
export default function useColor() {
// useState call is destructured into value + setter pair whose identifiers
// follow the [thing, setThing] naming convention
const [color, setColor] = React.useState();
return [color, setColor];
}import React from 'react';
export default function useColor() {
// useState result is directly returned
return React.useState();
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
react/hook-use-state
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/hook-use-state": "error",
},
},
];react/hook-use-state
react plugin · style
{
"plugins": [
"react"
],
"rules": {
"react/hook-use-state": "error"
}
}Biome does not have this rule.
Require all forwardRef components include a ref parameter