Go Back

9 min read

Understanding Form Handling in React — From useState to React Hook Form

profile

Nitin k

|

September 27, 2025

views

React form handling with useState and React Hook Form

Forms are a crucial part of almost every web application. Whether you're building a simple contact form or a complete registration page, understanding how to manage form state efficiently is key.

In this guide, we'll explore two approaches to handling forms in React:

  1. Using plain React state (useState)
  2. Using React Hook Form, a popular library for easy and scalable form validation

By the end of this guide, you’ll clearly understand when and why to move from simple form state management to React Hook Form.


🧩 1. Simple Form State Handling Using useState

Let's begin with the traditional way — managing form input state manually using React's useState hook.

💡 What You'll Learn

  • How to store input values
  • How to handle changes and submissions
  • How to show submitted data on screen

Here’s a basic example 👇

FormDetails.jsx

🧠 How It Works

  • useState stores form input values (formData).
  • handleChange updates the form state every time a user types something.
  • handleFormSubmit prevents page reload and logs/submits data.
  • The form also toggles password visibility using the FaEye and FaEyeSlash icons.

This approach is simple and works fine for small forms.
However, once forms get bigger and need complex validation, managing state manually becomes repetitive.

⚠️ Limitations of Manual Form Handling

While the above approach works for small projects or simple forms, it starts to become unmanageable as your form grows.
Here’s why:

  • ❌ You manually handle every onChange and useState for each field.
  • ❌ You write custom validation logic repeatedly.
  • ❌ Tracking form errors and showing them to the user is tedious.
  • ❌ Performance can suffer when forms become large.

That’s where React Hook Form (RHF) comes in — a powerful and developer-friendly library that makes form handling clean, efficient, and scalable.


⚙️ 2. Advanced Validation Using React Hook Form

React Hook Form is a lightweight library that makes form validation simpler, faster, and more maintainable.

It provides:

  • ✅ Automatic state management
  • ✅ Built-in validation
  • ✅ Easy integration with UI libraries
  • ✅ Better performance (fewer re-renders)

Let’s rebuild our form using React Hook Form 👇

FormDetails.jsx

🪜 Step-by-Step: Understanding Form States with ui

🖤 1. Blank Form (Initial State)

  • The form is rendered with empty fields.
  • No validation has been triggered yet.
  • All fields are blank and no error messages are visible.
  • formData (or RHF’s internal state) looks like this:
React form handling with useState and React Hook Form

🖤 2. Validation Errors (Error State)

  • The user starts typing or submits without filling all required fields.
  • Validation rules run, and errors are displayed below each invalid input.
  • Red error messages appear, and invalid fields might get a red border or shake animation.
React form handling with useState and React Hook Form

🖤 3. Form Filled (Valid State)

  • All fields meet validation requirements.
  • Input borders return to normal
  • Error messages disappear
  • Submit button becomes active
React form handling with useState and React Hook Form

🖤 3. Submitted Data (Output State)

  • The user clicks Submit, and handleSubmit() triggers.
  • Form data is logged or sent to an API.
  • A success toast or message appears (e.g., “Form submitted successfully 🎉”)
  • The form may reset or navigate to another page.
React form handling with useState and React Hook Form

🧩 Understanding the Key Concepts

register

Connects an input field to React Hook Form’s state and adds validation rules.

main.jsx

or

main.jsx

or

main.jsx

handleSubmit

A higher-order function that handles form submission and prevents the default browser reload.

watch

Allows you to monitor a specific field’s value (useful for password confirmation).

errors

Stores all validation errors.
You can show specific messages conditionally using errors.fieldName.

💬 Why Use React Hook Form?

Feature

useState Approach

React Hook Form

State ManagementManualAutomatic
ValidationManual logicBuilt-in + flexible
PerformanceFrequent re-rendersOptimized
Code LengthLongShort & scalable
ReusabilityHarderEasier

🚀 Conclusion

When building simple forms, managing state with useState is fine.
But as your application grows, switching to React Hook Form gives you:

✅ Cleaner code
✅ Real-time validation
✅ Better performance
✅ Easier maintenance

If you’re working on login, signup, or large multi-step forms, React Hook Form will save you hours of code and debugging.

Happy coding! 💻✨