0
我试图创建一个包含数组对象的窗体。我得到错误Encountered two children with the same key,
1:$ [object Object] .
。我如何创建一个唯一的密钥?在映射数组对象时创建唯一键
renderPositions() {
const profileCandidateCollection = this.props.profileCandidate;
const careerHistoryPositions = profileCandidateCollection && profileCandidateCollection.careerHistoryPositions;
if (careerHistoryPositions) {
return careerHistoryPositions.map((key, position) => {
return (
<CareerHistoryPositionsUpdateForm
key={key}
company={position.company}
title={position.title}
/>
)
})
}
}
谢谢,我在React文档中看过。您建议为每个对象创建一个唯一的ID是个好主意。 – bp123