Skip to content

Can the React docs state more rule of the custom Hook #3558

Description

@KennethKinLum

Could the custom Hook page https://reactjs.org/docs/hooks-custom.html
include one important rule:

#3557

Does any change of state in a custom Hook cause any component that uses it to re-render? Yes, when we use any Hook in our function, this function becomes a custom Hook, and when other components use it, any update of the state in this custom hook can cause the component to re-render. So we should not think of the custom Hook as a static function.

Or something along that line? Right now, it feels really magically that somehow, we define a function and it can magically cause another component to re-render itself.

A working example might even be added: https://codesandbox.io/s/suspicious-keller-blqey?file=/src/App.js

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