Pak RT’s hidden rod behind the screen is a ref: bump ketuk.current, hold an <input>, stop the gong’s interval after a re-render, and see when the screen…
Why it matters
Display data kept in a ref makes a stale UI ("why does it not change?"); a timer id kept in a plain variable is lost at the next render; kept in state it makes renders nobody needs. Knowing "a ref lasts without a render, state lasts with one" picks the right tool.
The key idea
useRef lasts across renders, but changing it triggers no render
Common mistakes
Keeping display data in a ref Changing a ref triggers no render, so the UI goes stale. Data that must show belongs in useState.
Reading or writing ref.current during render A render must be pure, and a ref to the DOM is still null on the first render. Read and write it in an event handler or useEffect.
Using state for a timer id or a value that is not display Every store adds a render. Keep it in a ref: it lasts without triggering a render (a plain variable is lost at the next render).
Try it in this playground
Press ketuk.current++ three times 3 in memory, still 0 on the screen: no render.
Then press setTepuk The next render reads what the ref holds: the number jumps.
Focus through kotak.current The real DOM element, with no render.
A message that reads countRef.current It prints the latest, not the value when it was sent.