2 回答

TA貢獻1775條經驗 獲得超11個贊
您正在渲染數組,但只能從react組件返回一個塊,將map函數包裝在div中
class Information extends Component {
render() {
const otherInformationLoop = otherInformation.map((value, key) => {
return (
<div>
<div className="col-md-4" key={key}>
<div className="dashboard-info">
{Object.keys(value).map((val, k) => {
return (<h4 k={k}>{val}</h4>)
})
}
</div>
</div>
</div>
)
})
return (
<div>{ otherInformationLoop }</div>
);
}
}

TA貢獻1835條經驗 獲得超7個贊
實際上,render方法返回的對象只有一個otherInformationLoop屬性。只需返回該值,而無需任何括號即可在React 16+中使用(但每個外部div都需要一個關鍵道具)
添加回答
舉報