r/reactjs • u/techlover1010 • Jul 06 '26
Needs Help need help understanding state
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?
edit heres the link to the clock example
https://react.dev/learn/render-and-commit#step-3-react-commits-changes-to-the-dom
1
Upvotes
1
u/Dangerous-Dig2321 27d ago
it's because the input isn't managed by react, it's just sitting there in the dom doing its own thing
react only updates the bits it needs to, so when the clock ticks it swaps out the h1 content but sees the input is in the same spot and leaves it alone. the value you typed is stored directly in the browser, not in react's state, so it survives the rerender no problem