Skip to content

Bug: react-hooks/exhaustive-deps false positive on TypeScript generic type variable #20395

@mschl0ss

Description

@mschl0ss

React version: 16.13.1

Steps To Reproduce

  1. Use type generics in a useEffect.

Code example:

function useBug<T>(): void {
  useEffect(() => {
    let bug: T;
  }, []); // <-- ESLint error: React Hook useEffect has a missing dependency: 'T'.

}

The current behavior

Dependency array throws ESLint error.

React Hook useEffect has a missing dependency: 'T'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

The expected behavior

No missing dependencies reported.

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