Answers for "react object.entries"

5

javascript iterate object key values

Object.entries(obj).forEach(([key, value]) => {
	console.log(key, value);
});
Posted by: Guest on March-30-2020
0

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;
Posted by: Guest on May-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language