useRef Hook

  • diff between ref and state variables
    • they are similar in being objects that hold value
    • ref objects persist across render; something to hold on to when you need
    • state variables trigger rerenders
  • good times to use refs:
    • managing focus or media
    • trigger animations (best for imperative)
    • integrating with DOM libraries
  • useEffect is the proper way to update a ref

Source -> Refs and the Dom