reactjs / reactjs/react.dev

[Documentation] Add information about `child.key` to `React.Children.map`

オープン
#2,023 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
11.8k
フォーク
7.9k
平均マージ
1日 11時間
マージ済み PR(30日)
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 :)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Issue にリンクされている React API ドキュメントページの React.Children.map セクションから始め、issue #10432 の関連する議論を確認してください。child.key と、children をラップする際にそれが重要である理由について明確な情報を追加し、その後、ドキュメントで意図された使用方法とパフォーマンス上の考慮事項が説明されていることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, react
領域
documentation
issue の種類
ドキュメント
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。