Course contentsShow
← React
Lesson 514 of 2,39614. Uncontrolled ComponentsFree lesson

Native Form Validation Reliance

When using browser-native HTML5 validation attributes, uncontrolled components work naturally without fighting React's model.

Native Form Validation Reliance

What you'll learn: How uncontrolled components work seamlessly with browser-native HTML5 validation attributes.

The Natural Fit

When you use uncontrolled components (inputs managed with refs instead of state), they behave just like regular HTML elements. This means all the built-in HTML5 validation attributes—required, pattern, min, max, minLength, maxLength, type="email", etc.—work exactly as the browser intended, without any React intervention.

With controlled components, you're managing the input's value through React state, which can sometimes complicate native validation. But with uncontrolled components, you simply attach these attributes to your JSX elements, and the browser handles everything automatically when the form submits.

How It Works

function SignupForm() {
  const emailRef = useRef(null);
  const passwordRef = useRef(null);

  function handleSubmit(event) {
    event.preventDefault();
    console.log('Email:', emailRef.current.value);
    console.log('Password:', passwordRef.current.value);
  }

  return (
    <form onSubmit={handleSubmit}>
      <input 
        ref={emailRef}
        type="email"
        required
        placeholder="Email"
      />
      <input 
        ref={passwordRef}
        type="password"
        required
        minLength="8"
        placeholder="Password"
      />
      <button type="submit">Sign Up</button>
    </form>
  );
}

The browser will automatically prevent form submission and display error messages if the email format is invalid, a field is empty, or the password is too short. You didn't write any validation logic—the native attributes handled it.

Why This Matters

You get validation "for free" without building custom logic or triggering re-renders. The browser's validation UI appears, prevents submission, and focuses the problematic field—all standard HTML behavior working naturally.

Key Takeaway: Uncontrolled components let you leverage HTML5 validation attributes without fighting React's rendering model, making simple forms even simpler.