I have a component that I would like to use to change its parent's state with a text input box. Right now, I have a callback function called sendData
that I'm using to pass information back to the parent. It's working, but is currently just passing the hard-coded string "hi". I would like to replace this string with whatever has been entered into the text input.
Here is my code:
class ChangeState extends Component {
sendData = () => {
this.props.parentCallback("hi");
}
render() {
return (
<div>
<input type="text" name="name" id="myTextInput" />
<button onClick={this.sendData}>
Click to send data from child to parent component
</button>
</div>
);
}
}
How would I go about doing this? Thanks!