r/reactjs • u/atapas • Sep 03 '26
Discussion What’s the real problem with useEffect in React?
Here is my honest question:
What's the actual problem with the useEffect hook? All over the X/twitter, I see a lot of negativity about this hook. It seems like a buggy thing in React.
My opinion is that developers blame useEffect because it's often used for data fetching as the primary use case. As we deal with various states like loading, data, error etc… synchronization of these causes bugs.
Also, a misunderstanding of the rendering cycle in React, such as where useEffect gets called could introduce additional misuses and bugs.
Hence, just saying useEffect is evil, may not be the right assumption is what I think. But, there could be cases that I'm missing.
What's your take or opinion about it?
27
u/creaturefeature16 Sep 03 '26
I've always understood it to be an "escape hatch" from React's rendering cycle, which is great for fetching data, but not so great for many other purposes and is used to "get around" the issues that re-renders bring, instead of attempting to understand the mechanics of why the re-rendering is happening in the first place, and composing the components properly.
I've related it to using !important in CSS: it's absolutely clutch for certain situations, but it otherwise complicates the overall code, bucks the natural order of things (in CSS' case, specificity) and makes debugging harder if you lean on it too much.
7
u/ColonelGrognard Sep 03 '26
It should be called misUseEffect.
Seriously though, there is nothing inherently wrong with it, it's an operator/dev problem.
6
u/SchartHaakon Sep 03 '26
No one is saying useEffect is evil, as far as I've seen? It's just a footgun. That's it. There are a few very valid use cases for it, and a shit ton of ways to misuse it and cause excessive rendering while technically maybe achieving what you wanted to achieve.
I'm not sure I get the question you're really asking because the question assumes people think the hook itself is badly written or something. It's not, it's just misused.
113
u/lIIllIIlllIIllIIl Sep 03 '26 edited Sep 03 '26
useEffect is an escape hatch for handling side-effects and interact with the world outside of React. It's useful if you need to make an API request or interact with the DOM when a component renders.
The problem is people using useEffects to adjust states within React. State updates should be atomic. If a user action modifies a state, it should lead to another valid state. It should not lead to a partially valid state that only becomes valid after running a few useEffects. If a child components needs to adjust a state of a parent components, most likely the component hierarchy is wrong, and the state and logic should be moved around.
80
u/binocular_gems Sep 03 '26
It's like `type: any` to me. There's nothing inherently wrong with it when used sparingly and properly, but developers often fall back to it when they shouldn't, and it can lead to a cascade of complexity. That said, programming communities on social media (way back to the ancient days of usenet, BBS, and *groups) tend to over-inflate problems and get dogmatic about it.
23
u/jackster31415 Sep 03 '26
Really not much to say other than the excellent docs page: https://react.dev/learn/you-might-not-need-an-effect
4
u/pm_me_yer_big__tits Sep 03 '26
There's nothing inherently wrong with it as long as you know how to use it. People who say it's 'evil' clearly don't.
3
u/stefanskipiotr Sep 03 '26
It makes code more complicated. People often forget they can just use event handlers and react to property changes instead. It's harder to debug and unnecessary in most cases. Using it as a "run on mount" hook with an empty dependency array is especially unclear — it's just bad design.
The funny part is that I've noticed AI reaches for it a lot. It learned the wrong lessons ;)
3
u/SendMeYourQuestions Sep 03 '26
It turns an already complicated state machine into one with unnecessary additional states and state transitions.
2
u/brandonscript Sep 03 '26
Like anything in software, the problems are one of:
- ignorance
- opinions
- othering
This one's just ignorance. If you know how to use it and what not to do, it's incredibly powerful.
2
u/LiveRhubarb43 Sep 03 '26
There's nothing wrong with it. It's great for data fetching. There's a lot of people who don't understand how it works or what it's actually for, and they'll hold up examples of devs using it incorrectly as examples of why we shouldn't use it.
A lot of people will say to use a query library instead - and I agree with them - but those libraries are using useeffect or something like it under the hood anyways.
2
u/thesonglessbird Sep 03 '26
I think a lot of it comes down the its name. If it was called something like “useSideEffect”, in the context of React components being pure functions, it would signal its intended use case better I think.
2
u/BoBoBearDev Sep 04 '26 edited Sep 04 '26
It is like C++, every time they told me it is easy and they can do it, they fucked it up and expect me to clean up their mess.
Even if they did it perfectly, it is like a jenga. Someone else touched it and it collapsed.
3
u/iareprogrammer Sep 03 '26
Pretty much all the reasons you listed. The problem is too many people don’t know the proper way to use it
1
u/xchi_senpai Sep 03 '26
Its the misuse of dependency array
1
u/sylvant_ph Sep 03 '26
I guess it's a combination of couple of things - adding additional boilerplate, an extra render to run stuff, not optional/conditional. I just wanna make a request, get my data and render the component using that data (or do something else if request fails). To achieve this you need to overengineer stuff. And if you add couple more business rules to the logic, it goes out of hand and you might end up stacking couple effects and complex codependency.
1
u/darthexpulse Sep 03 '26
Hard to track down, it needs to be where it is expected to be and documented properly.
1
u/octocode Sep 03 '26
it’s a tool built with a single simple purpose that people abuse to do literally everything.
1
u/Arsenicro Sep 03 '26
The problem with useEffect is that it is extremely easy to misuse. And it is not only a theory; it is a fact that it has historically been misused. People don't understand what useEffect does, how it works, or when to use it. You can find multiple posts that recommend "solutions" with useEffect, which may lead to new problems. AI learned from those posts. People learned from those posts. When the problem you want to solve seems solved by using useEffect, you may not even consider that this is wrong.
It is evil because it has a history of misuse, making it easy for new people to find such misuses and assume it is the correct way to use it. It is also evil because this misuse is hard to notice, especially if you are new to React, since it seems to solve the problem at hand. It almost encourages you to use it to, for example, synchronize some internal states in React. And even if you know what useEffect does and when it is supposed to be used, it is still easy to do something wrong and, for example, forget to add a cleanup function, which may lead to issues (like using useEffect to load data with a simple query search, which may, without a cleanup function, lead to inconsistencies between the search query and loaded data).
It is a pretty bad hook overall, and I always prefer avoiding it when I can.
1
u/OHotDawnThisIsMyJawn Sep 03 '26
If this was the only thing people used useEffect for, there would be no problem.
The issue is using it for literally anything besides syncing with an external system, and that's where all the problems are.
1
u/wolvar__ Sep 03 '26
Para mi es una manera de controlar el render y re-render en cascada de ReactJS, la verdad no se que uso le están dando si bien es cierto existe el callback-hell donde es cuando hacen demasiadas condiciones dentro de un useEffect se vuelve ilegible todo enredado y recomendaria mejor usar el hook useEffect por separados.
1
u/SangSuantak Sep 03 '26
I was given a task to add a new input field in a master form. You'd think it's a piece of cake, but no. Useefect was used so badly in the component it was difficult to track what's causing the form values to change. I knew it's going to be a maintenance nightmare, so i re-wrote the whole component for my own sanity. Luckily it wasn't a big form.
1
u/carbon_dry Sep 03 '26
I don't have an opinion on it. I just read the docs. The docs are a good place to answer this rather than X/Twitter.
useEffect is for syncing with external events, mostly. Most other uses of it will be improper, all though there my be legit uses for it inside react that takes skill to know. But reaching for an effect is not the default answer.
Have a read of https://react.dev/learn/you-might-not-need-an-effect which supports your concerns.
1
u/react_dev Sep 03 '26
It does exactly what it needs to do. React needs to interact with external systems like the browser, backend and based on the state changes there, it needs to reconcile internal state. Because they’re external systems we need to do a side effect, thus use effect.
It’s hated on because often times you look at the dependency array of the useEffect and its props, states, local declared stuff that’s obviously not external systems. In those cases there must be a gap in the code. No questions asked.
1
u/jibbit Sep 03 '26
Man, what a cop-out these answers are.
Programmer wants a lifecycle hook but gets a sync-machine. You think “run on mount” / “run when X changes” but you have to encode that as a deps array and hope it matches your intent. Experienced devs get deps arrays wrong constantly. thats a Leaky abstraction, not a skill issue
One hook, four jobs. Sync, reacting to changes, setup, derived state, all crammed into the same shape.
Timing’s invisible. Can’t tell from the call site if it’s before/after paint, every render, or interleaved with other effects.
Attracts its own worst use case: derived state. the one everyone agrees is wrong.
1
u/Cahnis Sep 03 '26
https://react.dev/learn/you-might-not-need-an-effect
1
u/lightfarming Sep 03 '26
useEffect creates side effects for state changes. so someone might be following the logic in the code, thinking changing a specific state is fine, while it actually triggers some unknown thing somewhere else in the code.
people often use it for things it isn’t necessary for, due to not being adept at react, and when it is everywhere it starts to make overly complicated code that is hard to maintain.
it should only be used for effects (interacting with things that are outside of the control of react)
1
u/AlexDjangoX Sep 03 '26
Misused. Used for fetching initial page data.
useEffect(() => { getPodcasts().then(setPodcasts); }, []);
1
u/LancelotLac Sep 03 '26
If it was only used for async data fetching it would be fine even though react-query is a better pattern. The issue is that people use it to synchronize useStates and all other bad stuff you shouldn't do.
1
u/atrtde Sep 03 '26
because most people use it to synchronize state when it should be used to synchronize external system with React
1
u/averagebensimmons Sep 03 '26
it's about using the correct tool for the job. when people start using React they over use the useEffect. I was certainly guilty of this too.
1
u/damdeez Sep 03 '26
Although I love functional React I sure do miss class components and how easy it was to reason through the React lifecycle
1
u/prcodes Sep 03 '26
Typically overused when there are simpler solutions https://react.dev/learn/you-might-not-need-an-effect
1
u/HomemadeBananas Sep 03 '26
It’s not always bad, but way over used. Data fetching, yeah most cases better to use react query or something else outside of the component to handle it. But that’s the least offensive of ways you probably shouldn’t use it.
People use it for making some state change when some different state changes, etc. It’s just overused in a way that makes code worse and more confusing when most of the time you don’t need it.
Then it’s such a common code smell that AI gets trained on it, and AI also does this common mistake too, and you need to tell it to not do that, and some devs don’t know any better or don’t catch it, so reviewing the code I’m still constantly telling people don’t use useEffect here.
1
u/azangru Sep 03 '26 edited Sep 03 '26
I think this negativity is silly.
There must be an api that lets you say "here's some work I need you to do apart from rendering". All component libraries have this: lifecycle hooks in old react / angular / lit; effect in solid; probably something similar in svelte. It's just that react's useEffect's api turned out to be silly; and the double call in strict mode doesn't help any.
P.S.: I've just learnt that Ember doesn't have effects.
1
u/the_real_some_guy Sep 03 '26
When code is written linearly, press button > do A > do B, the code is easy to follow, review, and change. If you move “do B” into a useEffect, the next person that edits that code might not notice “do B” is happening and then you get bugs.
Many of the bugs I need to fix end up being in an useEffect. Most of the time, that code did not need to be in a useEffect. There are times when it’s the right tool, but most of the time it is not.
1
u/Canenald Sep 03 '26
There's a long-lived fallacy that when you are using a framework, you have to use only the APIs the framework exposes for everything, or you are using it wrong. If you pick a plain construct in the language you are working in, you're doing it wrong. This is, of course, not true, but it causes people to use React state when a plain variable will suffice, and an effect when simply setting the state or assigning to a variable works just fine.
React team and the community have been trying to fight it, but to no avail. We still get posts like this. We still run into overuse of effects when we onboard to new projects. Good thing we can use AI these days to just refactor all the mess.
1
u/abopabopabop Sep 03 '26
The only problem is noob engineers overuse it
1
u/yardeni Sep 03 '26
It's just easy to get wrong. Often people misuse it for selecting from data instead of memoizing, or forget ro cleanup after effects, or use partial dependencies. Its a powerful Model but you gotta learn it to use it right
1
u/bestjaegerpilot Sep 03 '26
1
u/Several_Bread_3032 Sep 04 '26
It’s overpowered for peeps who don’t understand it . I use to have it changing states everywhere waiting for other effects to take place . Just sloppy 💩 all around from my end with it when I tried Web development haha
1
u/Franks2000inchTV Sep 04 '26
It’s fine, people just use it wrong in ways that cause a ton of problems.
1
u/minimuscleR Sep 04 '26
I mean if you have a good router, and use Tanstack Query, and a form library, you will hardly ever use an effect? I've written maybe 4 or 5 in the last year? Thats as a professional software engineer working in react all day every day.
1
u/BlacksmithNo1687 Sep 04 '26
People use it when they usually just need to lift stats up. Typically, if you’re setting state within a useEffect and that useEffect has a dependency on state you’re using it wrong. Almost every time I review a pr with the hook, it’s used incorrectly
1
u/Dense_Rub_620 Sep 04 '26
Each layer naturally optimizes for the problems it owns. A mature engineer hears a rule and asks. What is the scope of this rule, and where does it stop applying? A less mature response is The official docs say this, therefore this is the generally correct way to design software. That is what bothers me about some of these comments. It is not really a criticism of React. React is a view engine, so of course its guidance is render-centric. That makes perfect sense within React’s own boundary. What does not follow is that the rest of the application should also be designed exclusively from that perspective. Understanding the React docs is one skill. Understanding the scope and limits of those recommendations is another.
1
u/AverageHot2647 Sep 05 '26
I’m not sure there’s a problem with useEffect. People often say it’s too easy to use incorrectly, and hard to debug, etc. But I’ve never seen someone actually propose a better general purpose API.
I do think there’s a big problem with the way useEffect is used. I don’t want to say it’s a skill issue - I think that’s a bit of a cop out. But there’s definitely widespread negligence on the part of developers and code reviewers.
Where I see use of useEffect causing the biggest problems, is where developers already have poor code hygiene. For instance, I’ve seen components with has 200+ lines of hook logic and zero separation of concerns.
Ideally, you should abstract out large and complex blocks of hook logic into smaller custom hooks. This solves a lot of the readability problems around useEffect, and discourages many of the bad practices.
Maybe the solution is a better API (I’d love to see some proposals for something that can replace useEffect with fewer/more explicit foot guns). Or maybe we just need some better lint rules. Or maybe the React team could analyse the common use cases, and ship some higher level APIs to promote better readability. 🤷♂️
1
u/United_Reaction35 Sep 05 '26
UseEffect has become a culture-war issue for the react community. UseEffect and its accompanying murky 'side effects' is so perfectly ill-defined that it provides fertile ground for rigidly-opinionated software developers to quarrel over intent and use.
1
u/buck-bird Sep 05 '26
I've used React since it first came out.... let's stop pretending our chosen framework can do no wrong.
The whole concept of side effects makes sense, but the idea of piggy backing off it for API calls makes zero sense. Evil? No. Not thought out? Aye.
Don't get me started on no async hooks, abusing the word "use" in React 19, etc.
Again, I love React. But it doesn't mean everything is always perfect.
1
u/MussKacken Sep 06 '26
As someone that has mainly worked in backend and in terms of frontend has a fair share of experience with Javascript and typescript, but just a little bit of experience with react. Would it be better to look into something like svelte, vue, solid or something other than that?
1
u/RoosterBurns Sep 06 '26
It's a mysterious, weirdly named function that makes stuff look like it's working sometimes
1
u/Brilliant-Parsley69 Sep 07 '26
Well, my first contact with the useEffect-Hook was a user request to extend a form with one new field. What could I say, the form had already 35 fields, 1700 LOCs, up to four useEffect per field(Value, Error, Validation...) and not to forget to mention the almost identical implementations for updates.
I wasn't ever again that close to quit programming forever.
1
u/tjaartbroodryk Sep 08 '26
useEffect is where clarity goes to die. The hook isnt inherently bad, but it makes it easy to smuggle state flow into the background.
The worst cases are when child effects notify parents, parents update state, children re-render, and suddenly your app logic is spread across invisible timing chains.
1
u/marcofoc78 Sep 10 '26
Perché non usate Tanstack React Query per queste esigenze di sincro con i dati?
1
u/Roman_BDM_FixIT Sep 21 '26
On my opinion, useEffect is a great hook, but beginners using this for data fetching, and not always knew how the array of dependencies works. For API calls I prefer to use TanStack Query, which is handling all errors, loading, etc and useEffect wherever it needed for something else.
1
u/repeating_bears Sep 03 '26
If there is an inherent problem with it at all, it's not about what it does, but that something about its design leads people to overuse it when it's not appropriate. I'd say that the name isn't great, but I don't have a better suggestion and naming things is hard.
1
u/cult0cage Sep 03 '26
As others have said, it's mostly problematic because of peoples misuse of it. If it was truly an issue I'm sure the React team would deprecate it and offer a migration guide for existing codebases to follow.
-1
u/christfrost Sep 03 '26
It’s a fantastic hook, but 99% of developers are bad and thus they have no idea how to properly utilize it. And thus, if you don’t know how to use it, it messes up your application really bad and really fast.
0
u/gnudle Sep 03 '26
Love useEffect especially to let component fetch its own data. Rarely a problem even in a complex app with hundreds of files and tens of thousands lines of code
0
u/raaaahman Sep 03 '26
useEffectuseEffectall alongWhen you understand that
useEffectis a way to skip calls to an external system, it becomes smoother. (If you can afford calling to the external system every time your component re-renders, then you indeed don't needuseEffect).0
u/sporbywg Sep 03 '26
Introducing a team of young developers to React, I would not use any other tool then useEffect
-1
u/NotGoodSoftwareMaker Sep 03 '26
Its an easy way to get unbound behaviour without any good way to control or limit that behaviour
0
u/[deleted] Sep 03 '26
[deleted] — view deleted comment