我试图通过将数组传递给组件属性来加载字符串数组中的每个字符串到一个
<li>
HTML标签中:<CardItem
src='https://static.news...koinex-banner.png'
text='my text'
label='Adventure'
path='/products'
description={["someText1", "someText2", "someText3", "someText4"]}
/>
function CardItem(props) {
return (
<>
<li className='cards__item'>
<Link className='cards__item__link' to={props.path}>
<figure className='cards__item__pic-wrap' data-category={props.label}>
<img
className='cards__item__img'
alt='Travel Image'
src={props.src}
/>
</figure>
<div className='cards__item__info'>
<h5 className='cards__item__text'>{props.text}</h5>
</div>
<CardDescription description={props.description} />
</Link>
</li>
</>
);
}
export default CardItem;
function CardDescription(props) {
return (
<div>
<ul>
<li>{props.description[0]} </li>
</ul>
</div>
)
}
export default CardDescription
我遇到了一个问题:
类型错误:无法读取未定义的属性(读取“0”)
我不确定为什么props.description
属性返回undefined。
另外,这个TypeError似乎只在使用props.description
属性时发生。
CardDescrition
- CertainPerformance