我試圖讓這個組件渲染,我不斷收到錯誤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謝謝。 –