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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章