React useEffect Misuse: Syncing with External Systems Only

Unpopular opinion: useEffect is one of the most misused hooks in React. Most codebases I've worked in fall into the same traps: → Syncing state that could just be derived → Triggering logic that belongs in an event handler → Creating infinite re-render loops nobody wants to debug at 2am The real rule is simple: useEffect is for syncing with external systems — browser APIs, network requests, third-party widgets. That's it. If you're using it to watch one state variable and update another — that's a sign your state model needs a rethink, not another effect. Cleaner effects = easier to reason about = fewer production bugs. Spotted this on X via @alexdanilowicz — and it resonated #React #JavaScript #WebDevelopment #Frontend

  • graphical user interface, text, application, chat or text message

And use callback is the most underrated one , should have been used more but people fail to understand it's usecase

Like
Reply

There linter plugins that enforce correct useEffect use as well, I would add an obligatory lint run after writing any effects on the rule as well. I usually use this one: https://github.com/nickjvandyke/eslint-plugin-react-you-might-not-need-an-effect I wonder if oxlint already support it 🤔

useEffect is actually a good thing; when you are about to use it is a sign that you are doing something wrong with your data, or your component has a bad design, so it forces you to think what is wrong :)

The issue is people are thrown in work without placing proper efforts.

It's usually a code smell that tells you it's time to create a custom hook

Totally agree. Most "useEffect" usage is just a workaround for poor state design, not a real side-effect.

Not remotely close to being unpopular

See more comments

To view or add a comment, sign in

Explore content categories