Imagine if I have this code:
const [example, setExample] = useState(false);
useEffect(() => {
setExample(true);
console.log(example);
}, []);
Why does it print out false
instead of true
? It also does this when I log it after an interval, e.g.:
setTimeout(() => console.log(example), 1000); // false
I’m sure there must be a reason to this, but I simply do not know that reason, and I can’t find anything about it online.