I'm trying to clear the form onClick with react. The event triggers, but when I try to setState to " " it tells me cannot set state of undefined.
I've tried setting the state to empty in several ways.
onHandleChange(e) {
this.setState({
input: e.target.value
});
}
clearForm(e) {
e.preventDefault();
const input = this.state.input;
console.log("input", input);
this.setState({
input: ""
});
}
I've also tried to do it inline, with onClick={(this.form.elements["text-input"].value = "")}
.
<button
className="reset btn btn-danger"
type="reset"
id="resetInput"
value="reset"
onChange={this.onHandleChange}
onClick={this.clearForm}
>
Reset
</button>
My expected output is that the value of the input should be nothing. Empty string. However, that's not happening... i'm not resetting the state.