Answer the question
In order to leave comments, you need to log in
How to bypass React's state feature for input validation?
Hey!
Off . In the React docs, you can find an example of how onChange works with inputs -> codepan.
You can see that onChange does not return the currently entered character in the event .
In my example, this bothers me because I am validating the user's mail with a regular expression.
those. when I entered the input, [email protected]
I need to call the onChange event again for the validation to work.
handleChange(e) {
this.validate(e.target.value);
}
Answer the question
In order to leave comments, you need to log in
You may notice that onChange does not return the currently entered character in the event.
handleChange(event) {
this.setState({value: event.target.value});
console.log(this.state.value);
}
handleChange(event) {
this.setState({value: event.target.value}, () => console.log(this.state.value));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question