The Onsubmit Function In React Form Makes The Console To Clear And Refresh
The onsubmit function in react form forces the console to clear and refresh, thus making it impossible for me to see the logs and analyze them. I want to log some words on my conso
Solution 1:
Cause the form is doing is native way of submitting the form which is a normal page refresh or action to the form url. You can
use
e.preventDefault()
to prevent that
Something along like
handleSubmit(e) {
e.preventDefault();
console.log("submited");
}
To defer the submission
Solution 2:
See bro! form
has native default behavior to be refresh once you hit enter to submit it. Thus we can prevent this native behavior of form by including this simple 1 LOC:
event.preventDefault()
Qn arises? Where to include it line of code (LOC)
ans:In your handleSubmit
method, pass in the event argument, and add this in the beginning.
something like this:-
handleSubmit(e) {
e.preventDefault();
console.log("submited");
}
Post a Comment for "The Onsubmit Function In React Form Makes The Console To Clear And Refresh"