Chapter 1 · Practice 5 of 5
Pass ref as a normal prop in React 19
Why it matters
Since React 19, function components receive ref as a regular prop, so new code does not need forwardRef.
- Accept
refin your props. - Pass it to the DOM element you want to expose.
- Type it with the element type, for example through
React.ComponentProps<'input'>.
This matters for reusable inputs and buttons in a design system, where parents need to focus or measure the element. Keep the exposed surface small: give the parent the DOM node it needs, not internal state.
If you maintain older components, you can migrate them gradually; forwardRef still works today.
Example
type InputProps = React.ComponentProps<'input'> & { label: string };
function TextInput({ label, ref, ...rest }: InputProps) {
return (
<label>
{label}
<input ref={ref} {...rest} />
</label>
);
}