I wish to do the following in my application: 1) access the the property of color and option from each object 2) check the property 3) give a class based on that property 4) toggle the class onClick
The json object looks like this{
{
"green": false,
"other": "third",
"option" : 2
},
{
"green": false,
"other": "third",
"option": 1
},
{
"green": true,
"other": "first",
"option": 5
}
And so on... Each object will be giving back a number for the key ([0],[1] etc).
My React code is as follows:
class Inf extends React.Component {
constructor() {
super();
this.state = {
colorData: data
}
}
renderList(data){
return(
<ul>{Object.keys(this.state.colorData).map(thing =><li>{thing}</li>)}</ul>
)
}
render() {
console.log(this.state.colorData)
return (
<div>
<div>{this.renderList(this.state.colorData)}</div>
</div>
);
}
}
ReactDOM.render(
<Inf />,
document.getElementById('root')
);