React state updates in console but UI doesn't re-render (useState with counter)
posée 2 months ago77 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 2 months ago
Jean Pierre 5.1k
Aucune réponse
Sign in and verify your email to post an answer.