Skip to content

Bug: react-hooks/set-state-in-effect doesn't work in React.useState and React.useEffect #35377

@appellation

Description

@appellation

When calling setState from inside React.useEffect, as opposed to directly useEffect, the set-state-in-effect eslint rule does not detect a violation. This rule should detect violations regardless of how useState and useEffect are imported.

React version: 19.2.3
eslint-plugin-react-hooks version: 7.0.1

Steps To Reproduce

  1. Enable set-state-in-effect in your eslint config
  2. Import React with import * as React from 'react'
  3. Create a component that calls setState from inside React.useEffect
  4. Run eslint and observe that eslint does not fail

Link to code example: https://github.com/appellation/eslint-react-repro

The current behavior

set-state-in-effect only detects violations when directly importing useState and useEffect. It does not detect violations when using React.useState and React.useEffect from import * as React from 'react'.

The expected behavior

set-state-in-effect should detect violations when using React.useState and React.useEffect from import * as React from 'react'.

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