reactjs / reactjs/react.dev

Can the React docs state more rule of the custom Hook

未关闭
#3,558 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@KennethKinLum 已经在做这个了。

开始于 2021年3月2日。

  • #3557 来自 @KennethKinLum —— 未关闭
主要语言
JavaScript
星标
11.8k
派生
7.9k
平均合并
1 天 11 小时
30 天内合并 PR
11

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先查看 https://reactjs.org/docs/hooks-custom.html 上的自定义 Hook 页面以及相关的 pull request #3557。确认关于状态更新会导致使用自定义 Hook 的组件重新渲染的预期说明,然后使用已达成一致的措辞或示例更新文档,并验证页面能够正确渲染。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, react
领域
documentation
Issue 类型
文档
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。