object.entries in react code example
Example: object.entries render component react
{
areas: ['areaid_0', 'areaid_1', 'areaid_2'],
areaDetails: {
'areaid_0': {title: 'Some title', isSelected: false},
'areaid_1': {title: 'Some title', isSelected: false},
'areaid_2': {title: 'Some title', isSelected: false}
}
}
When it comes to rendering you can do like,
this.state.areas.map(x => {
const areaDetail = this.state.areaDetails[x];
<Component key={x} {...areaDetail}... />
})
When you wants to update any object, you can do like,
this.state.areaDetails[x].isSelected = true;