Course contentsShow
← React
Lesson 1224 of 2,39631. Forms in ReactFree lesson

Form Reset and Default Values

Setting initial values with defaultValues and resetting forms with reset(), including partial resets.

Form Reset and Default Values

You'll learn how to give forms initial values on mount and reset them to those defaults on demand.

The Core Idea

Think of defaultValues like a template you fill out before photocopying — every form starts with those values printed on it. The reset() function is like getting a fresh copy from that original template whenever you need to start over.

React Hook Form's useForm() accepts a defaultValues option that sets initial field values. These aren't just cosmetic — they're the "clean slate" your form returns to when you call reset().

Setting Default Values

const { register, reset } = useForm({
  defaultValues: {
    email: '',
    username: 'guest',
    age: 18
  }
});

All fields start with these values. Without defaultValues, fields are undefined initially, which can cause controlled/uncontrolled warnings.

Resetting the Form

Call reset() to return all fields to their defaults:

<button type="button" onClick={() => reset()}>
  Clear Form
</button>

Partial Resets and New Defaults

You can reset to different values by passing an object:

// Reset only email, keep other fields as-is
reset({ email: 'new@example.com' });

// Completely replace all defaults
reset({ email: '', username: '', age: 0 });

This is perfect for "Edit Mode" flows — load user data, let them edit, then reset back to the loaded data if they cancel.

Async Default Values

For data loaded after mount, call reset() once data arrives:

useEffect(() => {
  if (userData) {
    reset(userData);
  }
}, [userData, reset]);

Key Takeaway: Use defaultValues to define your form's initial state, and reset() to return to those defaults or dynamically set new ones — essential for edit forms and multi-step wizards.