Warning: Each child in a list should have a unique "key" prop.
原创
2024-7-24
11:17
编辑于
2024-7-24
11:19
react 项目报错 Warning: Each child in a list should have a unique "key" prop.
Check the render method of Header
. See https://reactjs.org/link/warning-keys for more information.
一般使用 map 渲染数组组件的时候,都会配置key熟悉。但是如果组件是数组的形式,那么也需要配置一个key。
let loginBtn = [
<div>a</div>,
<div>b</div>,
<div>c</div>
];
需要给每个数组元素配置key就不会提示了。
let loginBtn = [
<div key="a">a</div>,
<div key="b">b</div>,
<div key="c">c</div>
];
转载请注明出处。本文地址:
https://www.qinshenxue.com/article/react-each-child-in-a-list-should-have-a-unique-key-prop.html
关注我的公众号