我收到一个错误,该错误似乎与我的数组映射功能有关。如果数组包含一个对象,则该页面将正确呈现,但是,如果该数组为空,则该页面不会加载,并且在控制台中出现错误。
警告:React.createElement:类型无效-预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:对象。
我在这里想念什么?
路径:Companypage
export default class CompanyPage extends React.Component {
constructor(props) {
super(props);
const { companies } = props;
this.state = {
companies,
};
}
componentWillReceiveProps(nextProps) {
const { companies } = nextProps;
this.setState({
companies,
});
}
render() {
return (
<tbody>
{this.state.companies.map(company => (
<tr key={company._id}>
<td>
<img src={company.companyImageURL} alt="Company image" className="img-rounded company-image mr-2" />
<button
type="button"
className="btn btn-link"
onClick={this.handleDeleteCompanyImage(company.companyImageURL, company._id)}
><FontAwesomeIcon className="fa-fw" icon={faTimes} /></button>
</td>
<td>
<Link to={`/admin/application_components/edit/company_details/${company._id}`}>{company.company}</Link>
</td>
<td>{company.firmSize}</td>
<td>
<button
type="button"
className="btn btn-link"
onClick={this.handleDeleteCompanyCollection(company.companyImageURL, company._id)}
><FontAwesomeIcon className="fa-fw" icon={faTrash} /></button>
</td>
</tr>
),
)}
</tbody>
);
}
}