← React Intermediate Questions - Set 8 Q75

How do you handle async operations in React?

React Intermediate Questions - Set 8

Example

useEffect(() => {
  let cancelled = false;
  load().then(r => { if (!cancelled) setData(r); });
  return () => { cancelled = true; };
}, [id]);

What to notice

← Back to the question list