Tsallaka zuwa abun ciki
Justice Tech School

Refs to Children

Pass a ref to a child so the parent can reach its DOM node.

Example
function Input({ ref, ...rest }) {
  return <input ref={ref} {...rest} />;
}
function Form() {
  const r = useRef(null);
  return <Input ref={r} />;
}

Exercise

Pass the ref.

<input ={ref} />

Quiz Test

Why pass a ref to a child?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.