React state updates in console but UI doesn't re-render (useState with counter)

asked 3 days ago9 viewsen

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>
);

}

Environment:Node.js,react 22,19Windows 11

🤖 AI diagnosis

AI-generated. Not an answer — the community below confirms or corrects it. Always verify before relying on it.

No Answers

Sign in and verify your email to post an answer.