setValue and getValues for Manual Updates
What you'll learn: How to programmatically read and update form values in React Hook Form outside of normal input events.
The Manual Override Toolkit
Sometimes you need to update form values without the user typing—like setting a field based on another field's value, populating data from an API response, or implementing a "Copy Address" button. React Hook Form gives you setValue and getValues as escape hatches for these scenarios.
Think of your form like a car dashboard. Normally, values change when the driver (user) operates the controls. But sometimes a mechanic (your code) needs to reach behind the dashboard and adjust things directly. That's what these methods do.
setValue: Write Access
setValue updates a field's value programmatically:
const { register, setValue } = useForm();
// Update a single field
setValue('email', 'new@example.com');
// Common use: Copy one field to another
const copyBillingToShipping = () => {
setValue('shippingAddress', getValues('billingAddress'));
};
By default, setValue doesn't trigger validation. Pass options to control this behavior: setValue('email', value, { shouldValidate: true }).
getValues: Read Access
getValues retrieves current form values without subscribing to changes (unlike watch):
const { register, getValues } = useForm();
// Get single field
const emailValue = getValues('email');
// Get all fields
const allData = getValues();
// Get multiple specific fields
const { email, username } = getValues(['email', 'username']);
Use getValues inside event handlers or callbacks where you need the current value snapshot, but don't need reactivity.
When to Reach for These
Use setValue/getValues for side effects, button actions, or programmatic updates. For reactive UI updates based on field values, stick with watch() instead—it's optimized for that use case.
Key Takeaway: setValue and getValues let you manually read and write form state outside the normal input flow, perfect for button actions, API responses, and cross-field logic that doesn't need reactive subscriptions.