【发布时间】:2018-05-20 15:35:11
【问题描述】:
React 使用 key prop 来识别元素并正确协调。以下代码将给出控制台警告Warning: Each child in an array or iterator should have a unique "key" prop。
const List = () =>
<ul>
{[...Array(3)].map((_, idx) => <li>{idx}</li>)}
</ul>
虽然不会
const Table = () =>
<table>
<tbody>
{[...Array(3)].map((_, idx) => <tr><td>{idx}</td></tr>)}
</tbody>
</table>
为什么在使用表格行时不需要唯一键道具?
【问题讨论】:
标签: reactjs key tablerow listitem