Further explanation about why side-effects should be limited to useEffect
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 11.8k
- 派生
- 7.9k
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 11
描述
There are multiple recommendations about when side-effects are okay and when they are not okay; it is difficult to memorize them all, so it would be helpful if some further explanation is added explaining exactly why useEffect should be exclusively used for side effects e.g.
https://github.com/reactjs/reactjs.org/blob/master/content/docs/hooks-effect.md#example-using-classes-example-using-classes
For traditional life-cycle hooks, the reasoning is that some of them might be called multiple times before the render is committed; is the same applicable to hooks?
Thanks!
p.s. This comment seems relevant:
https://github.com/reactjs/reactjs.org/issues/302#issuecomment-345445888
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 Hooks Effect 文档部分开始,将其中对类生命周期方法的讨论与当前关于副作用和 useEffect 的指导进行比较。更新文档,清楚解释为什么副作用应放在 useEffect 中,并说明同样的重复调用问题是否也适用于 hooks;当无需记忆各自独立的规则就能理解这项建议时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100