What am I trying to do:
I am trying to pass a string from a child component to the handleChange function of the parent component.
What is currently working:
I have a React JS parent class with the following method:
handleChange(event) {
console.log(event.target.value);
}
In the rendering function, I have the following:
<Child handleChange={this.handleChange.bind(this)} />
In the Child class, I have:
<fieldset onChange={this.props.handleChange}>
<div>Tag 1: <input id="tag1" value={tags[0]} /></div>
<div>Tag 2: <input id="tag2" value={tags[1]} /></div>
<div>Tag 3: <input id="tag3" value={tags[2]} /></div>
</fieldset>
This works great.
What am I trying to do instead:
I am trying to add a parameter sectionto the handleChange function as follows:
handleChange(section, event) {
console.log(section);
console.log(event.target.value);
}
And in the Child class, I have:
<fieldset onChange={this.props.handleChange("tags")}>
<div>Tag 1: <input id="tag1" value={tags[0]} /></div>
<div>Tag 2: <input id="tag2" value={tags[1]} /></div>
<div>Tag 3: <input id="tag3" value={tags[2]} /></div>
</fieldset>
Now I get the error:
Uncaught TypeError: Cannot read property 'target' of undefined
This error occurs in my second console.log statement.
What am I doing wrong?
, section. , ? , , .