react-turbo icon indicating copy to clipboard operation
react-turbo copied to clipboard

BUG: Ref is undefined in useEffect

Open HoikanChan opened this issue 2 years ago • 0 comments

Error: Cannot read properties of undefined (reading 'current')

MyCode:

function C() {
  const ref= React.useRef();
  React.useEffect(() => {
    ref.current.focus(); // ref is undefined in debugger
  }, [])
  return <input ref={ref}/>
}

HoikanChan avatar Aug 09 '22 07:08 HoikanChan