What is useRef?
The useRef Hook provides an object whose current value persists between renders. Changing a ref does not normally cause a re-render.
Common Uses
- Focus an input.
- Access a DOM element.
- Store a timer identifier.
- Keep a mutable value that does not belong in the UI.
useRef vs useState
Use state when changing the value should update the UI. Use a ref when you need to remember a value but changing it should not trigger a render.
ADVERTISEMENT