Use the preventDefault() method on the event object to prevent a page refresh on form submit in React, e.g. event. preventDefault() . The preventDefault method prevents the browser from issuing the default action which in the case of a form submission is to refresh the page.One way to stop page resubmission on page refresh is to unset the form data after it is submitted so that the variable storing form data becomes empty and wrap up your form processing block of codes to check if the form is empty. This will make $data empty after processing and the first clause would stop form resubmission on page refresh.
How do you clear a form on refresh?
You could call the reset() method of the forms object from the body load event of your html document to clear the forms.
How do I stop form submitting?
The simplest solution to prevent the form submission is to return false on submit event handler defined using the onsubmit property in the HTML
from the section I wanted to prevent from posting and refreshing. Here only Buttons submit as they should.