Skip to content

Bug: react-hooks/exhaustive-deps reports a TypeScript type via typeof as a dependency #19327

@RebeccaStevens

Description

@RebeccaStevens

react-hooks/exhaustive-deps reports a missing dependency when a variable is used purely for it's type.

Once the typescript code has been transpiled, that variable will no longer be referenced in that part of the code and thus it's not a dependency.

React version: react@16.13.1
Eslint Plugin version: eslint-plugin-react-hooks@4.0.7

Steps To Reproduce

  1. Have some typed variable declared in the component.
  2. Within a hook callback, refer to that variable's type via typeof x

Link to code example: https://codesandbox.io/s/late-sun-rpws4?file=/src/App.tsx

The current behavior

An eslint error such as the following occurs:

react-hooks/exhaustive-deps - "React Hook useEffect has a missing dependency: ..."

The expected behavior

No error should occur.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions