React state updates in console but UI doesn't re-render (useState with counter)
posée 3 days ago8 vuesen
0
The value changes in the console, but the UI continues displaying the old value. Refreshing the browser displays the correct value. import { useState } from "react";
export default function Counter() { const [count, setCount] = useState(0);
function increase() {
setCount(count + 1);
console.log(count);
}
return (
<div>
<h2>{count}</h2>
<button onClick={increase}>
Increase
</button>
</div>
);
}
Environnement :Node.js,react 22,19Windows 11
🤖 Diagnostic IA
Généré par IA. Ce n'est pas une réponse — la communauté ci-dessous le confirme ou le corrige. Vérifiez toujours avant de vous y fier.
posée 3 days ago
Jean Pierre 1.7k
Aucune réponse
Sign in and verify your email to post an answer.