我的地图给我 无法读取未定义的属性(读取"地图")



我试图绘制不同人群的地图,但它在标题上给了我错误

我真的不明白,这是我的代码:


export const Testt = ({ childs}) => {
console.log(childs)
return childs.map((element, index) => (
//element
<div>
zdijiziojzadioj
</div>
)
)
}

还有我孩子的

(12) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {_id: '619e7301e74b007f5c62482d', firstName: '', lastName: '', birth: '2020-11-19', genre: 'male', …}
1: {_id: '619fae3c96f85d2415d8fe24', firstName: '', lastName: '', birth: '2021-11-03', genre: 'male', …}
2: {_id: '619fae5296f85d2415d8fe28', firstName: '', lastName: '', birth: '2021-11-04', genre: 'male', …}
3: {_id: '619faec296f85d2415d8fe39', firstName: '', lastName: '', birth: '2021-11-04', genre: 'male', …}
4: {_id: '619faee196f85d2415d8fe40', firstName: '', lastName: '', birth: '2021-11-04', genre: 'male', …}
5: {_id: '619faf1496f85d2415d8fe4e', firstName: '', lastName: '', birth: '2021-11-04', genre: 'male', …}
...
length: 12

我不明白哪里会有问题,我已经使用了地图,但我从来没有遇到过这个问题,

谢谢你的回答!

可能意味着在初始渲染时不会填充值childs

我们在React中通常会添加条件语句来避免这种情况。

这应该做的技巧-

export const Testt = ({ childs}) => {
console.log(childs)
return childs && childs.map((element, index) => (
//element
<div>
zdijiziojzadioj
</div>
))
}

最新更新