React useEffect misuse: Avoid using for rendering, state resets, and parent callbacks

The React team calls useEffect an "escape hatch." Not a lifecycle method. Not a data fetching tool. An escape hatch - specifically for syncing with systems outside of React. Yet, most codebases use it for everything else: ❌ Computing derived values → (Should be done during render) ❌ Resetting state on prop changes → (Should use the key prop) ❌ Calling parent callbacks → (Should happen in event handlers) React 18 made the problem impossible to ignore. Strict Mode now fires effects twice in development. If your logic breaks on that second run, your effect was always buggy - it just didn't have a mirror held up to it yet. React 19 (and the Compiler) removes the last excuse. The compiler handles memoization automatically. You can no longer blame "unstable references" for needing an effect to "watch" a dependency that shouldn't have changed. The Golden Rule: If everything inside your effect is already managed by React, you don't need an effect. useEffect is for talking to the "outside world" (APIs, manual DOM, subscriptions). What’s the most "creative" useEffect misuse you’ve encountered? 👇 #Frontend #JavaScript #ReactJS

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories