I have an Object in state which stores the current value of four 'Risk Type' checkboxes
riskTypes: {"Fraud": true, "Steal": true, "Scam": true, "Theft": true},
on the subcomponent to render them I use:
Object.keys(this.props.riskTypes).forEach(key => {
<li>
<label>
<input
type="checkbox"
value={key}
checked={this.props.riskTypes[key].value}
onChange={this.handleRiskTypeChange}
/> {key}
</label>
</li>
})
}
but this doesn't work, nothing is rendered, however if i console.log them instead of create checkboxes, it prints them fine. Any help much appreicated!
undefined. Instead you want to transform your list of types into a list of JSX elements..mapis used for 1-1 list transformations in JS. SoObject.entries(riskTypes).map(ele => {return <li>...</li>)}