I want to do something after calculateWinner()
performed whenever a certain variable changed. Because calculateWinner()
function can change the value of some variables that are related what I want to do.
So, I coded like as:
useEffect(async () => {
await calculateWinner();
setCurrentMove(currentMove + 1);
},[history])
But,
the terminal says:
Effect callbacks are synchronous to prevent race conditions.
What can I do to get the values that are changed by calculateWinner()
function, then with these I do next operation whenever a certain variable changed?
2
Answers
I found answer to this question.
You can’t use
await
function inuseEffect
.To solve this problem, you can do like below.
Also, you can define async function and use it.
I think this answer can help you.