Closed1
React でユニークな key を設定しているのに Warning: Each child in a list should have a unique "key" prop. が出る場合
map() で JSX のリストを出力している場合、map() が返す各配列のルートに key を設定する必要がある。
// Warning
{array.map((_) => {
<>
<span key={_}>List Item {_}</p>
<>
})}
// 修正後
{array.map((_) => {
<div key={_}>
<span>List Item {_}</p>
</div>
})}
このスクラップは2023/06/26にクローズされました