Alex Vipond
SHIFT + D

useEffect is weird

Published over 1 year ago

  • Closures can go stale
  • You have to explicitly think about JS object identity
  • Object properties don't always trigger effects when the object is fully replaced
  • It's easy to write effects that run too many times, not enough times, or run with the wrong data.
  • useEffect is weird.

Yet with all this weirdness, I've never found a comprehensive overview of stale closures, object identity footguns, etc. So I started working on one a while back 🎯

Here's a React + Vite SPA packed with code and explanations of how and why useEffect can go very wrong, very quickly, and how to fix it:

ON THIS PAGE

useEffect is weird