When I use useState several times with the same value as the previous value, the component is executed once and then nothing.
From what I understand so far, when the state is updated with the same value, nothing should happen.
import { useState } from 'react'
function App() {
const [count, setCount] = useState(0)
console.log('RENDER')
return (
<div>
<h1>{count}</h1>
<button onClick={() => setCount((c) => c + 1)}>+</button>
<button onClick={() => setCount(0)}>Reset</button>
</div>
)
}
export default App
If I press the + button several times (let's say 3 times), the state changes and the component is executed 3 times. The RENDER message is also displayed in the console each time.
If now I press the reset button several times. I have the message RENDER which is displayed twice then nothing.
The first time because the state changes, 3 to 0. The second time, the state is the same. So why is RENDER displayed again in the console?