A ref on your own component never reaches the input
Function components cannot be given refs. Attempts to access this ref will fail.Short answer
A ref placed on your own component only works if that component passes it to a DOM element. React 18 needs forwardRef for that. React 19 accepts ref as a normal prop. With react-hook-form, a component that cannot take a ref must be wrapped in Controller instead of register.
Fix it fast
1Find out which cause you have
Find the component that receives the ref and look at whether it hands the ref to a real DOM element such as input or select.
npm ls react grep -rn "register(" src | head2Match what you see, then jump to its fix
- 1
react 18.x installed; the spread {...register('name')} goes onto a custom componentReact 18 component without forwardRefFix - 2
react 19.x installed; the component takes props but never uses a refReact 19 component that does not pass ref onFix - 3
A UI-kit component with innerRef or inputRef, or one that only works through value and onChangeThe component calls its ref prop something else, or is controlledFix
- 1
What does the error look like?
Function components cannot be given refs. Attempts to access this ref will fail.The field has no value and cannot be focused on errors
Cause 1 of 3
React 18 component without forwardRef
1Check
By default the DOM nodes of a component are private. A plain function component receives no ref, so the form library cannot reach the input.
npm ls react2Fix
Wrap the component in forwardRef and attach the ref to the input.
import { forwardRef } from 'react';
const Select = forwardRef(function Select({ label, ...rest }, ref) {
return (
<label>
{label}
<select {...rest} ref={ref} />
</label>
);
});3Verify
Submit the form and focus an invalid field. The browser focuses the select.
npm run devConfirmed by react.dev
Cause 2 of 3
React 19 component that does not pass ref on
1Check
From React 19, function components receive ref as an ordinary prop. If you destructure props and leave ref out, it never gets attached.
grep -rn "ref" src/components/Select.jsx2Fix
Read ref from the props and put it on the input. forwardRef is no longer needed in new components.
function Select({ label, ref, ...rest }) {
return (
<label>
{label}
<select {...rest} ref={ref} />
</label>
);
}3Verify
Trigger a validation error and confirm the field is focused.
npm run devConfirmed by react.dev
Cause 3 of 3
The component calls its ref prop something else, or is controlled
1Check
The react-hook-form docs say register reads the value through the ref of the real input. A spread onto a component that names its ref differently never assigns it.
grep -rn "innerRef\|inputRef" src node_modules/your-ui-kit/package.json 2>/dev/null2Fix
For a differently named ref prop, pass the parts of register one by one. For a fully controlled component, use Controller.
const firstName = register('firstName', { required: true });
<TextInput
name={firstName.name}
onChange={firstName.onChange}
onBlur={firstName.onBlur}
inputRef={firstName.ref}
/>3Verify
Type into the field and submit; the value appears in handleSubmit.
npm run devConfirmed by react-hook-form.com
How do I stop it coming back?
- In a shared input component, always forward the ref (React 18) or the ref prop (React 19) to the real element.
- Prefer Controller for third-party select and date components.
- Keep one React major version across the app and its UI kit.
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