We use Ref when you want to track something and update it without triggering a rerender. If you want to trigger a rerender you can just use state instead. Another specific use case for useRef() is when you want to change DOM nodes and need a way to refer to them specifically. React doesn't really create DOM nodes until the render phase, so if you need to refer to them in your components, you need to provide a reference, or
useRef and useEffect: DOM Interactions
useRef and useEffect: DOM Interactions
useRef and useEffect: DOM Interactions
We use Ref when you want to track something and update it without triggering a rerender. If you want to trigger a rerender you can just use state instead. Another specific use case for useRef() is when you want to change DOM nodes and need a way to refer to them specifically. React doesn't really create DOM nodes until the render phase, so if you need to refer to them in your components, you need to provide a reference, or