After setting the state of a variable in useEffect, I console.log it on the next line which gives
undefined
Why is this so and how do i use the state variable?
const [item, setItem] = useState();
useEffect(() => {
const doFunction = async () => {
try{
setItem("hi")
console.log(item)
},[item]);
doFunction()