react-hook-form shows no error when you leave a field
No error message appears after tabbing out of an invalid fieldShort answer
react-hook-form validates on submit by default, so leaving a field shows nothing. Set mode to onBlur in useForm. For MUI, Select or any custom input, use Controller and pass field.onBlur, field.onChange and field.ref to the real input. Otherwise the library never hears the blur event.
Fix it fast
1Find out which cause you have
Log the form's validation mode and the touched fields, then focus and leave one invalid field. If errors stay empty after the blur, work through the causes in order.
const { control, formState: { errors, touchedFields } } = useForm({ mode: "onBlur" }); console.log(errors, touchedFields);2Match what you see, then jump to its fix
- 1
Errors only show after the first submitmode was never set, so the default onSubmit appliesFix - 2
Plain inputs validate on blur but the MUI or custom component does notA controlled input does not pass onBlur back to the formFix - 3
register is spread on a wrapper component, the value is undefined and the field cannot be focused on errorA custom component with register does not forward the refFix
- 1
What does the error look like?
No error message appears after tabbing out of an invalid fieldErrors only appear after pressing the submit buttonValidation works on blur for plain inputs but not for a UI-library component
Cause 1 of 3
mode was never set, so the default onSubmit applies
1Check
Open the useForm call. The default mode is onSubmit, which validates only when handleSubmit runs.
const form = useForm(); // mode is "onSubmit"2Fix
Pass mode in the single options object of useForm. Use onTouched if you want the first check on blur and then a check on every change.
const { register, handleSubmit, formState: { errors } } = useForm({
mode: "onBlur", // or "onTouched"
});3Verify
Focus the field, type something invalid and press Tab. The error should appear without submitting.
<p>{errors.email?.message}</p>Confirmed by react-hook-form.com
Cause 2 of 3
A controlled input does not pass onBlur back to the form
1Check
Look at how the component is connected. Components that are not plain DOM inputs need Controller, and the render prop gives you field.onBlur, field.onChange, field.name and field.ref. The docs say onBlur is how the library hears that the input was interacted with.
<Controller name="email" control={control} render={({ field }) => (
<TextField {...field} />
)} />2Fix
Spread field onto the input, or assign each prop by hand if the component renames them. If you wrap onBlur or onChange in your own handler, call field.onBlur() and field.onChange() inside it.
<Controller
name="email"
control={control}
rules={{ required: "Email is required" }}
render={({ field, fieldState }) => (
<TextField
{...field}
error={!!fieldState.error}
helperText={fieldState.error?.message}
/>
)}
/>3Verify
fieldState.isTouched becomes true after the first blur, and the error shows.
console.log(fieldState.isTouched);Confirmed by react-hook-form.com
Cause 3 of 3
A custom component with register does not forward the ref
1Check
register reads the value through the ref of the real input element. A function component that drops ref or onBlur breaks that link.
<MyInput {...register("email", { required: true })} />2Fix
Pass all props, including ref, to the underlying input. If the component calls the prop something else, such as inputRef, map it by hand, or switch to Controller.
const { ref, ...rest } = register("email", { required: true });
<MyInput {...rest} inputRef={ref} />3Verify
Submit an empty form: the first invalid field takes focus, and blur now validates it.
// no extra command neededConfirmed by react-hook-form.com
How do I stop it coming back?
- Decide the mode once for the whole form: onSubmit for short forms, onBlur or onTouched for long ones.
- Wrap every non-DOM input in Controller and always forward onBlur, onChange and ref.
- Do not use mode: all unless you need it; change events add re-renders.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fixWeb apps
Axios request is not cancelled when a React component unmounts
A cancelled request is logged as an error in the catch block
Axios cancels a request when you pass it an AbortSignal and later call abort() on its controller.
4 causes, each with a fix