Shyla Nie Shyla Nie - 3 months ago 15
React JSX Question

ReactJS Warning: Each child in an array or iterator should have a unique "key" prop

var divArr = [
'<div>布吉岛啊</div>',
'<div>呵呵呵</div>',
];
ReactDOM.render(
<div>{divArr}</div>,
document.getElementById("example")
);


but it's error:


Warning: Each child in an array or iterator should have a unique "key" prop. Check the top-level render call using . See [warning-keys][1] for more information.


and I don't know how to insert the 'key'

Answer

you need to put unique key inside the array div check my code

var divArr = [
 '<div key='1'>布吉岛啊</div>',
 '<div key='2'>呵呵呵</div>',
];
ReactDOM.render(
   <div>{divArr}</div>,
   document.getElementById("example")
);
Comments