Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

TypeScript: 'ref' does not exist on IntrinsicAttributes for my component

ErrorProperty '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.

  • Applies to React 19, React 18, TypeScript 5.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/
  2. 2Match what you see, then jump to its fix

    1. 1The error is on the JSX line <MyInput ref={ref} />The component does not forward refs (React 18 and earlier)Fix
    2. 2You are on React 19 and want to avoid forwardRefOn React 19 the ref can simply be a propFix
    3. 3ref.current is null in the parentThe component uses forwardRef but never attaches the refFix

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.tsx

2Fix

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 --noEmit

Confirmed by react.dev

Did this fix it?

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 react

2Fix

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 --noEmit

Confirmed by react.dev

Did this fix it?

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.tsx

2Fix

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

Did this fix it?

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:

Related fixes

Web 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.