I'm trying to use this.setState on an array of objects once I've received the data, however, my code below only sets the state on 1 object. I think it's writing over itself.
Path: MongoDB
"careerHistoryPositions": [
{
"company": "Company A",
"title": "Title A",
"uniqueId": "1497575516964"
},
{
"company": "Company B",
"title": "Title B",
"uniqueId": "1497575525034"
}
]
Path: Reactpage
constructor(props) {
super(props);
this.state = {
data: [],
};
}
componentWillReceiveProps(nextProps) {
const profileCandidateCollection = nextProps.profileCandidate;
const profileCandidateCollectionId = profileCandidateCollection._id;
const careerHistoryPositions = profileCandidateCollection && profileCandidateCollection.careerHistoryPositions;
if(careerHistoryPositions) {
careerHistoryPositions.map((position) =>
this.setState({
data: [{
'position.uniqueId': position.uniqueId || '',
'position.company': position.company || '',
'position.title': position.title || ''
}]
})
);
}
}