React · Middle · Question 75 of 75

Why can useEffect with an async callback be a problem?

useEffect(async () => {
  setData(await load());
}, []);

Explanation

Define an async function inside the effect and call it: useEffect(() => { let ignore = false; (async () => { ... })(); return () => { ignore = true }; }, []).

Further reading

Problem with a question

React · Middle · question 75

Test yourself

Take the React · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz