When running the run function, I expect that value variable has value 'new', but since even 500 ms, it still remains 'old'. Why that happens and how coud this issue be solved?
import React, { Component, useState } from "react";
import { render } from "react-dom";
function App() {
const [value, setValue] = useState('old');
const run = async() => {
setValue('new')
const data = await wait(500)
console.log(value)
}
return (
<button onClick={run}>
Run
</button>
);
}
render(<App />, document.getElementById("root"));
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}