antd 之 Each child in a list should have a unique key prop

在这里插入图片描述
解决问题:
一般出现这个问题由于内循环生成多个组件,没有给组件加上key引起的,因为dom进行diff对比 没有key值,所以报错警告。 此时我们需要循环生成多个组件中,加上key值(唯一值)那么就不会报错了。

比如:

const Option=Select.Option;

<Select
  style={{width: 200}}
  allowClear
  onChange={(value)=>{onCustomerChange(value, this)}}
>
  {
    customerList && customerList.length>0 && customerList.map((item, index)=>{
      return <Option value={item.ssid} key={index} >{item.name}</Option>
    })
  }
</Select>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章