Skip to content

[eslint-plugin-react-hooks] Bug: react-hooks/refs rule reporting false positive #35813

@ej612

Description

@ej612

Hi there!

When updating to v7 of eslint-plugin-react-hooks, I'm getting an error that I haven't been getting on v5, and I believe it's a false positive.

This is my functional component:

function App() {
  const groupRefs = {
    group1: React.useRef<ComboBoxItemGroupDomRef>(null),
    group2: React.useRef<ComboBoxItemGroupDomRef>(null),
  };

  // const group1Ref = React.useRef<ComboBoxItemGroupDomRef>(null);
  // const group2Ref = React.useRef<ComboBoxItemGroupDomRef>(null);
  
  return (
    <ComboBox>
      <ComboBoxItemGroup
        ref={groupRefs.group1}
        // ref={group1Ref}
        headerText="Group 1"
      >
        <ComboBoxItem text="Item 1" />
      </ComboBoxItemGroup>
      <ComboBoxItemGroup
        ref={groupRefs.group2}
        // ref={group2Ref}
        headerText="Group 2"
      >
        <ComboBoxItem text="Item 2" />
      </ComboBoxItemGroup>
    </ComboBox>
  );
}

I'm keeping a list of refs for each group, and I'm passing each one into the group element.
This gives me the following error:

Image

I think the rule mistakenly interprets groupRefs.group2 as referencing ref.current, which is not the case. If I don't collect all refs in an object but create an individual variable for each, I don't get an error.

Steps to reproduce:

Image
  • Run npm install, open in vscode.
  • You should get the error I screenshotted above.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions