I am making a checklist using React. Here's my Parent component:
<ul>
{this.props.data.map(item => {
return(
<div><Child {...item} onChange={(e) => this.handleChange("Hello", e)}/></div>);
})}
</ul>
which calls on Child component that prints list elements:
<li>
<input
type="checkbox"
value={this.props.value}
onChange={event => this.props.onChange(this.props.id, this.props.value, event.target.checked)}
/>
{this.props.value}
</li>
and here's the handleChange method:
handleChange(myString, e) {
console.log(e.target.id, e.target.value, e.target.checked, myString);
}
I want to pass a custom string of my own to handleChange method but I am unable to do that. I have seen several posts regarding this topic but I need help correcting what I am doing wrong. The problem seems to be the way I send onChange data from Child component back to Parent component. Above is what I have written so far. I get an error Cannot read property id of undefined. I would appreciate some help regarding how to fix this.