Storing value of input in valueOfInput variable can be done by declaring it into class level using this.
constructor(props) {
super(props);
this.state = { val: "test" };
this.valueOfInput = null;
}
change(e) {
this.valueOfInput = e.target.value;
}
submit(ev) {
ev.preventDefault();
alert(this.valueOfInput);
}
But it won't work as expected as we're not updating value of input with new value. So to solve this we have to store new input value into state and use that value in input.
change(e) {
this.valueOfInput = e.target.value;
this.setState({
val: e.target.value
});
}