I'm trying to update a state by clicking on a th tag such as:
<th value='john' onClick={(e)=>handleClick(e)}>user<th/>
and handleClick() looks like this:
function handleClick(event) {
setUser(event.target.getAtrribute('value'))
console.log(user)
}
Now, I would think that the console would output "john", yet, it doesn't. It outputs whatever user was previously set to. I have to click the th tag twice for it to update to 'john'. Why is it that this happens and is there a solution?