Make it clearer how to run an effect only once (componentDidMount style)
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 11.8k
- 分支
- 7.9k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 11
描述
Based on this conversation on Twitter, it's perhaps not clear enough how to make an effect hook only run once on mount (a la componentDidMount.)
The relevant info on how to do it properly is tucked away near the bottom of the effect hook doc, in a footnote of this tip. This is a major use case that should probably have higher priority in the documentation. I imagine a vast majority of apps actually need to do use an effect in this manner.
I assume people are probably doing something like
function MyComponent({ fetchData, data }) {
useEffect(() => {
if (!data) {
fetchData()
}
})
}
I can make the change to the docs, but where's the best place to put it? Should I make it a tip? Does it deserve higher priority than that?
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 effect hook 文件及其中的「提示:透過跳過 Effect 最佳化效能」部分開始,目前只在 mount 時執行一次的指引被隱藏在這裡。判斷 useEffect-on-mount 範例是否應放在優先順序更高的部分或提示中,然後確認文件清楚地說明了預期的模式。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, react
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100