A ten-field form with simple validation never causes problems. A fifty-field form, with conditional sections, cross-field validation, and a network call to check email uniqueness, quickly becomes a form that lags on every keystroke, validates too early or too late, and whose state drifts out of sync with the display. This post looks at where it actually breaks and how to structure state so it stays manageable.
The problem: cascading re-renders and fragmented state
The naive pattern puts each field in its own useState at the parent level, then passes value and onChange down as props to each child.
function RegistrationForm() {
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
const [email, setEmail] = useState('');
const [country, setCountry] = useState('');
const [vatNumber, setVatNumber] = useState('');
// ... fifteen more fields
return (
<form>
<TextField value={firstName} onChange={setFirstName} />
<TextField value={lastName} onChange={setLastName} />
{/* ... */}
</form>
);
}
Every keystroke on firstName triggers a re-render of the entire RegistrationForm component, which re-renders all of its children unless they're individually memoized. With fifty fields and synchronous validation on each one (regex, length, format), typing becomes noticeably sluggish on modest hardware, and worse on mobile.
The second symptom, more insidious: cross-field validation. The vatNumber field only becomes required if country is in the EU. With state fragmented across independent useState calls, this rule ends up scattered across useEffect hooks that trigger each other, producing re-validation loops or inconsistent state mid-keystroke.
Why it happens: React re-renders by default, not by exception
React has no way of knowing that updating firstName doesn't affect how vatNumber is displayed. Without explicit memoization (React.memo, useMemo, useCallback) or an architecture that isolates subscriptions to change, every setState at the root triggers reconciliation of the whole subtree under that component.
Validation adds a second layer of complexity: validating on every onChange (React Hook Form's mode: 'onChange') gives instant feedback but multiplies computation, while validating only on submit (mode: 'onSubmit') gives a poor experience on fields with a high cost of error (password, email).
Diagnosing it: profile before optimizing blindly
React DevTools Profiler shows exactly which components re-render on each keystroke and why (the "why did this render" trace). Before rewriting the architecture, confirm the slowdown actually comes from re-renders and not, say, an expensive regex validation running synchronously on the main thread.
// Measure the real cost of a section re-render
import { Profiler } from 'react';
function onRenderCallback(id, phase, actualDuration) {
if (actualDuration > 16) {
console.warn(`${id} (${phase}) took ${actualDuration.toFixed(1)}ms`);
}
}
<Profiler id="AddressSection" onRender={onRenderCallback}>
<AddressSection />
</Profiler>
If actualDuration regularly exceeds 16ms (the frame budget at 60fps) for a section that didn't visibly change, that's a clear sign of an unnecessary re-render.
The fix: uncontrolled state + targeted validation
Hand field state to a form library
React Hook Form (or Formik, with different tradeoffs) addresses the root problem by keeping fields uncontrolled by default: the value lives in the DOM via refs, and React only re-renders components explicitly subscribed to a given field through useWatch or conditional rendering of an error message.
import { useForm, useWatch } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
const schema = z.object({
country: z.string().min(1, 'Country is required'),
vatNumber: z.string().optional(),
}).refine(
(data) => !isEuCountry(data.country) || Boolean(data.vatNumber),
{ message: 'VAT number is required for an EU country', path: ['vatNumber'] }
);
function RegistrationForm() {
const { register, control, handleSubmit, formState: { errors } } = useForm({
resolver: zodResolver(schema),
mode: 'onBlur',
});
const country = useWatch({ control, name: 'country' });
const vatRequired = isEuCountry(country);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<select {...register('country')}>{/* options */}</select>
{vatRequired && (
<input {...register('vatNumber')} placeholder="VAT number" />
)}
{errors.vatNumber && <span>{errors.vatNumber.message}</span>}
<button type="submit">Submit</button>
</form>
);
}
Cross-field validation (Zod's refine) lives in one place, the schema, instead of being scattered across useEffect hooks. Only the component reading country via useWatch re-renders when that field changes; other fields registered via register trigger no re-render at the parent level.
Debounce expensive async validation
For a network check (email uniqueness, for instance), validating on every keystroke would overload the server and produce flickering feedback. Combining debounce with mode: 'onBlur' or deferred validation avoids that:
import { useState } from 'react';
import { useDebouncedCallback } from 'use-debounce';
function EmailField({ register, setError, clearErrors }) {
const [checking, setChecking] = useState(false);
const checkEmailAvailability = useDebouncedCallback(async (email) => {
setChecking(true);
try {
const res = await fetch(`/api/users/check-email?email=${encodeURIComponent(email)}`);
const { available } = await res.json();
if (!available) {
setError('email', { message: 'This email is already in use' });
} else {
clearErrors('email');
}
} finally {
setChecking(false);
}
}, 500);
return (
<input
{...register('email')}
onBlur={(e) => checkEmailAvailability(e.target.value)}
/>
);
}
The 500ms debounce absorbs fast typing; useDebouncedCallback ensures the debounced function isn't recreated on every render, which would otherwise break the debounce itself.
Testing the validation logic without making the suite brittle
A poorly tested complex form always ends up regressing silently: someone tweaks a cross-field validation rule for one edge case and breaks another case that no test covered. Testing the Zod schema in isolation (without mounting a React component) covers the pure business logic quickly and without DOM-related fragility:
// vat-schema.test.js
import { schema } from './registration-schema';
test('requires a VAT number for an EU country', () => {
const result = schema.safeParse({ country: 'FR', vatNumber: '' });
expect(result.success).toBe(false);
expect(result.error.issues[0].path).toEqual(['vatNumber']);
});
test('does not require a VAT number outside the EU', () => {
const result = schema.safeParse({ country: 'US', vatNumber: '' });
expect(result.success).toBe(true);
});
For interface behavior (the vatNumber field actually appearing or disappearing on screen), React Testing Library with user-event remains the right layer, interacting with the form the way a user would rather than inspecting the internal state of the hooks:
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { RegistrationForm } from './RegistrationForm';
test('shows the VAT field only for an EU country', async () => {
const user = userEvent.setup();
render(<RegistrationForm />);
expect(screen.queryByPlaceholderText(/VAT number/i)).not.toBeInTheDocument();
await user.selectOptions(screen.getByRole('combobox', { name: /country/i }), 'FR');
expect(screen.getByPlaceholderText(/VAT number/i)).toBeInTheDocument();
});
This split (schema tested in isolation, visible behavior tested through user interaction) avoids the classic trap of form tests that fire raw fireEvent.change calls on uncontrolled inputs: with React Hook Form, the value lives in the DOM via refs, so only a real user interaction correctly triggers the update and re-validation.
The tradeoffs
Moving fields to uncontrolled via React Hook Form makes real-time value transformation harder (formatting a credit card number while typing, for example): that requires a Controller, which reintroduces a controlled component for that specific field, accepting its localized re-render cost.
On a highly dynamic form where nearly every field depends on another (a product configuration form with dozens of conditional rules), even this architecture can become hard to follow. In that case, explicitly modeling state as a state machine (XState, or a useReducer with named actions) makes transitions traceable, at the cost of more verbose code than a plain validation schema.
When the form library isn't enough
If validation depends on business rules that change the schema itself based on context (a multi-tenant form where each client has different required fields), a static schema defined at component mount time isn't enough: the schema needs to be generated dynamically from server configuration, and that dynamic schema needs to be properly memoized so the resolver isn't recreated on every render.
The point to keep: a slow React form almost always comes from over-centralized state and undifferentiated validation between instant feedback and expensive checks. Isolating field subscriptions and separating local synchronous validation from debounced async validation fixes most cases, before even reaching for finer-grained optimization.
