I have a seemingly elementary problem that keeps setting my projects back--useState isn't rendering correctly for me.
Here is a simplified version of the issue:
function App() {
const [count, setCount] = React.useState(0);
function TestFunction() {
for (let i = 0; i < 10; i++) {
setCount((curr) => curr + 1);
console.log(count);
}
}
return (
<>
<h3>Count = {count}</h3>
<button onClick={() => TestFunction()}>Click</button>
</>
);
}
export default App;
Upon clicking the button, the state is then set to 10, but the console.log() isn't properly updated.
Any help is appreciated.
Thanks
-S