← Back
react

react forward ref

I've just learned that if you want to receive the ref prop, you'll need to use forwardRef React method:

type Props = {
value: string;
};
const FormRow = React.forwardRef<HTMLInputElement, FormRowProps>(
({ value }, ref) => (
<div>
<input type="text" ref={ref} />
</div>
)
);

Notice that ref is not received as part of props.