You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Feature, in form of a question.
Might be infeasible. Vaguely relates to #14110.
What is the current behavior?
If a function component does use more or less hooks between re-renders, an error is thrown.
This contrasts with other implementations that allow this, such as TNG-Hooks.
What is the expected behavior?
Would it be possible to return early if values returned by hooks do not require subsequent hooks and values to be processed?
The documentation states that we must "ensure that Hooks are called in the same order each time a component renders". It seems that using more or less hooks wouldn't break that rule, as long as, during a render, the sequence of used hooks either contains or is a sub-sequence of the longest hooks sequence from all previous renders.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
v16.8.1
The text was updated successfully, but these errors were encountered:
Using less Hooks causes confusing semantics, e.g. some people would expect previous effects to not re-run if exited early. It's confusing enough to be worth enforcing always calling Hooks. You can put your early exit after the Hooks calls anyway.
Adding more Hooks later will likely be supported later for progressive enhancement. But we'll need to spend more time to figure out the API and best practices so for now it's disallowed.
Do you want to request a feature or report a bug?
Feature, in form of a question.
Might be infeasible. Vaguely relates to #14110.
What is the current behavior?
If a function component does use more or less hooks between re-renders, an error is thrown.
This contrasts with other implementations that allow this, such as TNG-Hooks.
What is the expected behavior?
Would it be possible to return early if values returned by hooks do not require subsequent hooks and values to be processed?
The documentation states that we must "ensure that Hooks are called in the same order each time a component renders". It seems that using more or less hooks wouldn't break that rule, as long as, during a render, the sequence of used hooks either contains or is a sub-sequence of the longest hooks sequence from all previous renders.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
v16.8.1
The text was updated successfully, but these errors were encountered: