If you work with react and sometimes you want your web to do not refreshing the page when you click button submit. The solution of this problem are just try this scripts below (for example) :
const handleSubmit = event => {
console.log('handleSubmit ran');
event.preventDefault(); // 👈️ prevent page refresh
// 👇️ access input values here
console.log('firstName 👉️', firstName);
console.log('lastName 👉️', lastName);
// 👇️ clear all input values in the form
setFirstName('');
setLastName('');
};
That is solution " submit form without refreshing page in react". Hope this example can helping you.
Source :https://bobbyhadz.com/blog/react-prevent-page-refresh-on-form-submit#:~:text=Use%20the%20preventDefault()%20method,is%20to%20refresh%20the%20page.
No comments:
Post a Comment