Interview frequency: …
Short answer
React Hook Form uses the Uncontrolled pattern and registers inputs with Refs, avoiding a full form render on every keystroke, unlike Formik's Controlled State approach.
Explanation
Formik updates central state for every character typed, re-rendering every field and slowing large screens. RHF registers fields and listens for changes locally, re-rendering only the field related to an error and using very little memory.
Code example
import { useForm } from 'react-hook-form';
function LoginForm() {
const { register, handleSubmit, formState: { errors } } = useForm<{ email: string }>();
const onSubmit = (data: { email: string }) => console.log(data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register("email", { required: "Email is required" })} />
{errors.email && <span>{errors.email.message}</span>}
<button type="submit">Sign in</button>
</form>
);
}Common mistakes
- Calling watch() at the top of a component without selecting specific fields, re-rendering the entire component and losing RHF's main benefit.
Follow-up questions
- How do Controlled Components and Uncontrolled Components differ, and when should you prefer each?
- How do you manage Dynamic Field Arrays whose number of fields changes in a form?