[Documentation] Add information about `child.key` to `React.Children.map`
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 11.8k
- 分支
- 7.9k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 11
描述
I just spent quite a while debugging a performance issue when reordering a large list of components, which were wrapped in React.Children.map.
The issue was the implementation of the wrapping component, which used the index as the key, which caused the entire list to re-render from scratch:
<div>
{React.Children.map(props.children, (child, index) => (
<div key={index} className='...'>{child}</div>
))}
</div>
The solution was to use child.key and pass it into the child-component, which then, in turn, made the memoization of the child components work as expected:
<div>
{React.Children.map(props.children, (child) => (
<div key={child.key} className='...'>{child}</div>
))}
</div>
I feel like this should be mentioned somewhere on the documentation page for React.Children.map, since I only figured out that this is possible at all after specifically searching for it and finding #10432.
I'm happy to update the docs in a PR if this gets the OK :)
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 issue 中連結的 React API 文件頁面上的 React.Children.map 區段開始,並檢視 issue #10432 中的相關討論。新增有關 child.key 以及在包裝 children 時其重要性的清楚資訊,然後確認文件說明了預期用法和效能方面的考量。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, react
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 55/100