Skip to content

Conversation

@marvinhagemeister
Copy link
Contributor

@marvinhagemeister marvinhagemeister commented Feb 19, 2025

If an if-statement is placed before a hook it doesn't necessarily mean that the hook was called conditionally. It only is, if the if-statement contains a return statement.

This should error:

function Foo() {
  if (condition) {
    return
  }

  useState(0)
}

...but this is ok:

function Foo() {
  let count = 0;
  if (condition) {
    count++
  }

  useState(0)
}

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marvinhagemeister marvinhagemeister merged commit 7e361b3 into main Feb 19, 2025
7 checks passed
@marvinhagemeister marvinhagemeister deleted the rules-hooks-fix branch February 19, 2025 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants