I am generating a series of divs by using .map()
on my state (created via the useState()
React hook).
Each of these divs has a unique React key
. However, I still receive the following error:
Warning: Each child in a list should have a unique "key" prop.
Each of these <div>
siblings has 30-50 children. Does each of those children need a unique React key
as well?
The React documentation (https://reactjs.org/docs/lists-and-keys.html) appears ambiguous on this point.
It indicates that:
"A good rule of thumb is that elements inside the map() call need keys." (All elements? Or just the parent siblings?)
Keys must only be unique among siblings. (The scenario I describe follows this rule)
However none of its examples provide clarity on list siblings with many nested elements within.
Thanks in advance for your help.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…