Skip to content

Bug: react-hooks/rules-of-hooks does not support do/while loops #28713

Closed
@tyxla

Description

@tyxla

React version: 18.2.0

Steps To Reproduce

  1. Use a hook inside a do/while loop.

  2. You'll see that it's not considered a violation of the rule.

Code example:

function ComponentWithHookInsideDoWhile() {
	do {
		useHookInsideLoop();
	} while (true);
}

The current behavior

The react-hooks/rules-of-hooks does not consider hook usage inside a do/while loop a violation.

The expected behavior

I expected that I'd see the following ESLint error:

React Hook useHookInsideLoop() may be executed more than once. 
Possibly because it is called in a loop. 
React Hooks must be called in the exact same order in every component render.

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