jsx-eslint/eslint-plugin-react

[Bug]: `hook-use-state` is not doing what the documentation says it does

オープン

#3,872 opened on 2025/01/06

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (2,731 件のフォーク)batch import
documentationhelp wanted

Repository metrics

Stars
 (9,293 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

hook-use-state documentation says that the rule checks whether the value and setter variables destructured from a React.useState() call are named symmetrically.

It does not say that the rule checks whether the result of a react.useState class is destructured.

Either the description is wrong, or the implementation is wrong.

Expected Behavior

If the rule is actually checking whether the value and setter variables destructured from a React.useState() call are named symmetrically, then the following code sample should be correct.

import React from 'react';
export default function useColor() {
  // useState call is not destructured into value + setter pair
  const useStateResult = React.useState();
  return useStateResult;
}

If it is not, then, the description must be updated to:

This rule checks whether the return value of a React.useState() call is destructured, and the value and setter variables are named symmetrically.

eslint-plugin-react version

every

eslint version

v9

node version

v20

コントリビューターガイド