Skip to content

Allow using more or less hooks between re-renders #14834

Closed
@davidbonnet

Description

@davidbonnet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions