Question · JavaScript and React course · Module 5: useEffect and Custom Hooks

useRef in Library Integration

Why is it worth storing a library instance in useRef when integrating external libraries (e.g., Chart.js, D3) with useEffect?

Answer options

  • useRef automatically synchronizes the library with React rendering cycle
  • useRef allows keeping a reference between renders without triggering a re-render
  • useRef is faster than useState when storing large objects
  • useRef automatically cleans up library resources on unmount

You can check the correct answer by solving this task in the CodeWorlds game.