Simple Forms Without Real-Time Validation
You'll learn: When and how to use uncontrolled components for forms that only need final values on submit.
The Right Tool for the Job
Not every form needs to react to every keystroke. Sometimes you just need to collect data and process it when the user clicks "Submit" — like a contact form, login page, or settings dialog. For these cases, uncontrolled components are the perfect fit.
Think of it like filling out a paper form: you don't have someone watching over your shoulder validating each letter as you write. You complete the form, hand it in, and then someone checks if it's valid. That's exactly what uncontrolled components let you do.
The Pattern
Use refs to access input values only when needed (typically on submit), and use defaultValue to set initial values without creating controlled components:
function ContactForm() {
const nameRef = useRef(null);
const emailRef = useRef(null);
function handleSubmit(event) {
event.preventDefault();
const name = nameRef.current.value;
const email = emailRef.current.value;
// Validate and process here, only once
console.log({ name, email });
}
return (
<form onSubmit={handleSubmit}>
<input ref={nameRef} defaultValue="" placeholder="Name" />
<input ref={emailRef} defaultValue="" placeholder="Email" />
<button type="submit">Submit</button>
</form>
);
}
No onChange handlers. No state updates on every keystroke. No re-renders until submit. The browser handles the input display, and you read the values when you actually need them.
Key Takeaway: Use uncontrolled components with refs when you only need final form values on submit — they're simpler, require less code, and avoid unnecessary re-renders during typing.