React state updates in console but UI doesn't re-render (useState with counter)
poze 2 days ago5 gadeen
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>
);
}
Anviwònman:Node.js,react 22,19Windows 11
🤖 Dyagnostik IA
Se IA ki fè l. Se pa yon repons — kominote a anba a konfime oswa korije l. Toujou verifye anvan ou fye l.
poze 2 days ago
Jean Pierre 1.7k
Pa gen repons
Sign in and verify your email to post an answer.