REACT 我因为“无法读取未定义的属性‘map’”而感到困扰
2019-12-14
30
import React from 'react';
import './BusinessList.css';
import Business from '../Business/Business';
class BusinessList extends React.Component {
render() {
return (
<div className="BusinessList">
{
this.props.businesses.map(business => {
return <Business business={business} key={business.id} />
})
}
</div>
);
}
}
export default BusinessList;
我一直在尝试解决未定义的映射,尽管我没有取得任何实际进展。这里有人至少有一个想法可以帮我解决吗?提前谢谢了
1个回答
尝试使用条件。
<div className="BusinessList">
{
this.props.businesses && this.props.businesses.map(business => {
return <Business business={business} key={business.id} />
})
}
</div>
akhtarvahid
2019-12-14