I have this variable:
const [userName, setUserName] = useState<string>("initialValue");
With a button click I execute this function:
const FacebookSign = () => {
console.log(userName);
setUserName("value2");
console.log(userName);
}
The userName
variable doesn't change and my output is:
initialValue
initialValue
But if I hit the button the second time, I got the output:
value2
value2
Why doesn't the value change the first time?