I'm new to React, and I'm having problem with setState and useEffect.
I want to make findWinner() to wait until setHand() is done
I've found that useEffect() can help this but it shows invalid hook call (I want to know why)
This is my code snippet.
const [hand, setHand] = useState({myhand:-1, comhand:-1})
function setWinner(h){
useEffect(() => {
findWinner(hand.myhand, hand.comhand)
}, [hand]);
setHand({myhand:h, comhand:Math.floor(Math.random()*10)%5});
}