【发布时间】:2021-12-22 14:56:48
【问题描述】:
我正在尝试通过 props 传递该数组来加载 <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
我得到了
TypeError: Cannot read properties of undefined (reading '0')
我不确定为什么 props.description 属性返回 undefined。
此外,这个 TypeError 似乎只发生在 props.description 属性上。
【问题讨论】:
-
我无法复制。此外,您可能想要修复拼写。
CardDescrition -
你从哪里得到错误?
标签: javascript reactjs typeerror