medium10 pts · first answer countsreact-hooks
Ref value not shown on screen
Clicking the button never updates the number on screen. Why?
function Clicks() {
const clicks = useRef(0)
return (
<button onClick={() => { clicks.current += 1 }}>
Clicked {clicks.current} times
</button>
)
}Discussion 0
Join free to post in the discussion.
Related questions
- Stale value in useEffectFrontend Developer
- Resize handler that runs many timesFrontend Developer
- Syncing derived values with an effectFrontend Developer
- Race condition in data fetchingFrontend Developer
- Effect that fetches foreverFrontend Developer
- Tooltip flashes in the wrong placeFrontend Developer
- Timer counter stuck at oneMobile App Developer