鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ react v16下render與antd table的問題

react v16下render與antd table的問題

render() {
    return(
     [    
         xxx... ,
         <Table/>
     ]
    )
}

Warning: Each child in an array or iterator should have a unique "key" prop. See https://fb.me/react-warning-keys for more information.

如果我用v16的語法去寫render,會報上述錯誤,如果我在最外一層套一個<div></div>,就是以前v15的寫法,則不會報錯,antd table我已經(jīng)添加了rowKeys,請問各位大佬有遇到這樣的情況嗎?

回答
編輯回答
黑與白

Each child in an array or iterator should have a unique "key" prop.
你只是添加了rowKeys,rowKeys是表格行渲染需要的,但是你的XXX的key呢,Table的key呢,這個也是需要的

2018年4月18日 10:14
編輯回答
厭惡我

你這樣是返回的一個數(shù)組,
你的xxx是什么東西

2017年8月30日 21:52
編輯回答
神曲

前面都說了加key的問題,而且要注意Tablekey,不處理Tablekey依然報錯

render() {
    return(
     [    
         <div key="0" /> ,
         <div key="1" /> ,
         ... ,
         <Table key="n" rowKey={r => r.id}/>
     ]
    )
}
2017年5月26日 01:51
編輯回答
膽怯

這是 waring 不是 error。

你 render 函數(shù)返回的是一個數(shù)組,你需要為數(shù)組里的每一個元素帶上唯一的key。

2017年12月21日 15:17
編輯回答
情未了
render() {
    return(
     [    
         <div key="0" /> ,
         <div key="1" /> ,
         ... ,
         <Table key="n"/>
     ]
    )
}

這樣子寫就不會有問題了

2018年6月21日 05:46