[英]Why am I getting undefined error for map method while getting array as a prop?
This is what I'm passing as a prop这就是我作为道具传递的
<Card tags={ ["HTML", "CSS", "JavaScript", "React"] } />
Here I'm getting the prop在这里,我得到了道具
const Card = (props) => {
const { tags } = props; return (
<Cardstyled> <Tags>
{tags.map((tag) => ( <Tag>{tag}</Tag> ))}
</Tags>
</Cardstyled>
)
Everything seems fine but I'm still getting the undefined error一切似乎都很好,但我仍然收到未定义的错误
TypeError: Cannot read properties of undefined (reading 'map')
TypeError:无法读取未定义的属性(读取“地图”)
Could anyone help me with this?谁能帮我解决这个问题? Thanks!
谢谢!
Its not define at the rendering time, do:它没有在渲染时定义,做:
{tags && tags.map((tag) => ( <Tag>{tag}</Tag> ))}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.