reactjs / reactjs/react.dev

Further explanation about why side-effects should be limited to useEffect

未關閉
#2,607 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從連結的 Hooks Effect 文件章節開始,將其中對類別生命週期方法的討論與目前對副作用和 useEffect 的指引進行比較。更新文件,清楚說明為什麼副作用應放在 useEffect 中,並說明相同的重複呼叫疑慮是否也適用於 hooks;當不必記住各自獨立的規則就能理解這項建議時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript, react
領域
documentation
Issue 類型
文件
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。