我试图让这个组件渲染,我不断收到错误A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
我不知道是什么问题,因为如果没有什么可返回,我将返回null
。React组件错误undefined,但应该返回null
有什么想法?
组件:CompanyLogo
function CompanyLogo(props) {
props.companies.map((company) => {
if (props.companyId == company._id) {
console.log("Test to see if firing");
return <p>Return as a test</p>;
}
return null
})
}
很好的答案。奇迹般有效。 – bp123
使用'.some()',而不是'.map'。如果你的比赛是说,标志#2,你有50多,为什么继续循环? –
@DimitarChristoff谢谢。 –