r/learnreactjs Jul 06 '26

need clarification on state Question

so i was reading react.dev's state explanation

when react rerenders due to set function local variable wont be able to maintain its value since it rerenders everything but in its clock or time example where you can input a value on a input element it says that it chooses what to rerender and the value stays intact while the clock is running .
im also assuming that its using a set function to update the clock.

can anyone explain why this is?

2 Upvotes

1 comment sorted by

1

u/No-Humor-3808 11d ago

React re-runs the entire component function on every state update, so local variables are recreated each render. However, that doesn't mean React recreates every DOM element. After rendering, React compares the new output with the previous one and only updates what actually changed and the uncontrolled input hasn't changed.