TypeScript: 'ref' does not exist on IntrinsicAttributes for my component
Property 'ref' does not exist on type 'IntrinsicAttributes'Short answer
A plain function component does not accept a ref, so TypeScript says the property does not exist. Wrap the component in forwardRef and attach the ref to a DOM node. On React 19 you can instead take ref as an ordinary prop. If the ref stays empty, the component never attached it.
Fix it fast
1Find out which cause you have
Open the component you pass ref to. If it is a normal function with props only, cause one applies. If it already uses forwardRef, go to cause three.
grep -rn "forwardRef" src/2Match what you see, then jump to its fix
What does the error look like?
Property 'ref' does not exist on type 'IntrinsicAttributes'
Cause 1 of 3
The component does not forward refs (React 18 and earlier)
1Check
In React 18, a ref only reaches a component that is wrapped in forwardRef; its render function receives props and ref.
grep -n "function MyInput\|const MyInput" src/MyInput.tsx2Fix
Wrap the component and pass ref to the DOM node.
import { forwardRef } from "react";
const MyInput = forwardRef<HTMLInputElement, { label: string }>(
function MyInput({ label }, ref) {
return (
<label>
{label}
<input ref={ref} />
</label>
);
}
);3Verify
Compile the project; the error is gone.
npx tsc --noEmitConfirmed by react.dev
Cause 2 of 3
On React 19 the ref can simply be a prop
1Check
In React 19 you can access ref as a prop for function components, and forwardRef is no longer necessary for new components.
npm ls react2Fix
Declare ref in the props type and attach it to the DOM node.
import type { Ref } from "react";
function MyInput({ placeholder, ref }: { placeholder: string; ref?: Ref<HTMLInputElement> }) {
return <input placeholder={placeholder} ref={ref} />;
}3Verify
<MyInput ref={ref} /> compiles and ref.current points to the input.
npx tsc --noEmitConfirmed by react.dev
Cause 3 of 3
The component uses forwardRef but never attaches the ref
1Check
If the ref is not used, or only attached conditionally, the parent's ref stays empty.
grep -n "ref=" src/MyInput.tsx2Fix
Pass the received ref to the DOM node or to a component that accepts it, on every render path.
const MyInput = forwardRef<HTMLInputElement, { label: string }>(
function MyInput({ label }, ref) {
return <input aria-label={label} ref={ref} />;
}
);3Verify
Log ref.current after mount; it holds the input element.
console.log(inputRef.current)Confirmed by react.dev
How do I stop it coming back?
- Type the ref with the element it points to, for example HTMLInputElement.
- On new React 19 code, prefer the ref prop and leave forwardRef for older React versions.
- Use the same pattern for every reusable input in your design system.
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
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint reports no-unused-vars for React components and imports that are used
no-unused-vars reported for a component that is rendered as a JSX tag
ESLint's core no-unused-vars does not see variables used only as JSX tags, so a component imported and rendered as <Hello /> looks unused.
3 causes, each with a fixWeb apps
TypeScript rejects MUI Data Grid columns that set a type
A TypeScript error inside a column's renderCell callback
A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.
2 causes, each with a fixWeb apps
The renderInput prop stopped working on the MUI X DatePicker
The custom TextField (variant, size, helperText) is ignored
renderInput was removed from the MUI X date pickers in version 6.
3 causes, each with a fix