I am updating a variable in one function and using it in another
const callNum = () => {
let number = 5;
number = number * number;
setNum(number);
};
const callFun = () => {
console.log("hello");
callNum();
setTimeout(() => {
console.log("callfun", num);
alert(num);
},1000);
};
these are the function above. I am calling it by clicking a button I know setState is asynchronous but as the setState updates shouldn't react re-render. When using console.log it shows the variable is undefined. Please explain why this is happening?