reactjs / reactjs/react.dev

Can the React docs state more rule of the custom Hook

Open
#3,558 1 comment 0 reactions 0 assignees View on GitHub

@KennethKinLum is already working on this.

Since Mar 2, 2021.

  • #3557 by @KennethKinLum — open
Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

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

https://github.com/reactjs/reactjs.org/pull/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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the custom Hook page at https://reactjs.org/docs/hooks-custom.html and the related pull request #3557 first. Confirm the intended explanation of state updates causing components that use a custom Hook to re-render, then update the documentation with the agreed wording or example and verify the page renders correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.