Skip to content

Bug: ESLint react-hooks/exhaustive-deps rule false positive on constants made with constant expressions #21274

Open
@ToadKing

Description

React version: 16.14.0 & 17.0.2

Steps To Reproduce

  1. Create a constant variable with an expression made of only constants.
  2. Run ESLint

Code example:

const a = 1
const b = 2 / 3
const c = -1
const d = +1

useEffect(() => {
  void a
  void b
  void c
  void d
}, [])

CodeSandbox: https://codesandbox.io/s/funny-wilson-33zxb

The current behavior

I see the following ESlint warning:

React Hook useEffect has missing dependencies: 'b', 'c', and 'd'. Either include them or remove the dependency array. (react-hooks/exhaustive-deps)

The expected behavior

I see no warning.

In my example the a variable is skipped in the ESlint warning, but not the other three variables even those they are all constant expressions.

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