useRef Playground

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

Try it in this playground