简体   繁体   中英

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')

Could anyone help me with this? Thanks!

Its not define at the rendering time, do:


{tags && tags.map((tag) => ( <Tag>{tag}</Tag> ))}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM