Why is there two implementations of ref in react?

45 views Asked by At

There are two variants of ref usage in react:

ref object:

const CustomInput = () => {
  const ref = useRef();

  return <input ref={ref} />
}

and callback ref:

const CustomInput = () => {
  const ref = useRef();

  return <input ref={el => { ref.current = el; }} />
}

What is the need to have two ref implementations? Is this some kind of legacy issue or anything else?

0

There are 0 answers