React Foundations · Effects & Refs

Ref as a prop

ref as a prop

Ref as a prop

Before React 19, a component could not receive a ref like any other prop. You had to wrap it in forwardRef to opt in. React 19 removes that ceremony: ref is now an ordinary prop.

function TextInput({ ref }) {
  return <input ref={ref} />;
}

The parent passes a ref exactly as it would to a DOM element:

const inputRef = useRef(null);

<TextInput ref={inputRef} />;

React fills inputRef.current with the <input> node, because the child forwards the prop straight through. No forwardRef, no wrapper — the component reads ref from its props like any other value.

This is the React 19 replacement for forwardRef. Reach for it whenever a component needs to hand a DOM node back to its parent. If you also want to expose a custom API instead of the raw node, combine it with useImperativeHandle.

Your job is to forward a ref to an input in App.jsx without forwardRef.

Challenge

A Focus button should reach the child input, and in this version of React the child can just take ref as a prop. Export an App component from App.jsx that renders a TextInput child and a Focus button. The child takes ref as a normal prop and forwards it to an <input>, with no forwardRef. The button focuses the input through the ref.

The Test clicks your Focus button and expects the input to be the active element. The starter renders the input and button but never forwards a ref, so the Test fails.

App.jsx
export function App() {
  return (
    <div>
      <input />
      <button>Focus</button>
    </div>
  );
}

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.