Next.js starter your AI actually understands. Ship internal tools in days not weeks. Pre-order $199 $499 → [Get it now]

How to handle form submission in React

Proper form submission handling is essential for creating responsive user interfaces and preventing unwanted page reloads in React applications. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented form submission logic in hundreds of production components over my 25 years of development experience. From my expertise, the best approach is to use the onSubmit event handler on the form element combined with preventDefault() to maintain full control over the submission process. This pattern ensures smooth user experience and proper data handling.

Use onSubmit event handler with preventDefault() to control form submission behavior.

const handleSubmit = (e) => {
  e.preventDefault()
  console.log('Form submitted:', formData)
  // Process form data here
}

return <form onSubmit={handleSubmit}>/* form fields */</form>

Here the handleSubmit function receives the event object and calls preventDefault() to stop the browser’s default form submission behavior. This prevents page reload and allows you to handle the form data with JavaScript. You can then process the form data, validate it, send it to an API, or update component state as needed.

Best Practice Note:

This is the same approach we use in CoreUI form components for reliable form handling. Always validate form data before submission and consider showing loading states during async operations to improve user experience.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to change opacity on hover in CSS
How to change opacity on hover in CSS

How to convert a string to boolean in JavaScript
How to convert a string to boolean in JavaScript

What is the difference between sort and toSorted in JavaScript?
What is the difference between sort and toSorted in JavaScript?

How to Remove Elements from a JavaScript Array
How to Remove Elements from a JavaScript Array

Answers by CoreUI Core Team