DEV Community

Cover image for React’s `useEffect`: Best Practices, Pitfalls, and Modern JavaScript Insights

React’s `useEffect`: Best Practices, Pitfalls, and Modern JavaScript Insights

Harish Kumar on January 13, 2025

React’s useEffect hook is a cornerstone of functional component development, enabling developers to handle side effects like data fetching, DOM man...
Collapse
 
keyru_nasirusman profile image
keyru Nasir Usman

Isn't it better to use a library like tanstack/react-query rather than plain useEffect to make developer's life easier?

Collapse
 
daviddanielng profile image
David Daniel

More dependence, yay JavaScript.

Collapse
 
dev_iyke profile image
Obasi Ikechukwu

Tell me more about this react-query

Collapse
 
elvissautet profile image
Elvis Sautet

interesting, have you tried using Remix.js, will reduce client code by 70%

Collapse
 
thejaredwilcurt profile image
The Jared Wilcurt

Pro-Tip: Use literally anything other than React and you won't need to spend half your time learning workarounds to get the thing to work without blowing up.

#JustTryVue
#IMeanWillYouAtLeastTryIt
#ItsSixTimesFaster
#AndFree
#HaveYouSeenTheVueDevTools
#OMGPiniaAloneIsWorthIt
#PleaseStopHittingYourself

Collapse
 
mohamed_kamel_cefecb4db25 profile image
Mohamed Kamel

I am sorry but this is literally one the worst advices i have ever seen.
Every tool has pros and cons of its own and having cons doesnt mean it sucks.
I am a 5+ years a React user, sure there were times of confusion and frustration when i first started learning it but it was all worth it.
React will definitely make you a better js developer, it may seem like taking the hard route but it pays off in the end.
You will get to know more about the advanced concepts and topics of js through react since it relies heavily on those concepts.
React will also expose you to different ways of architecting your app since react doesnt have an explicit or opinionated way of structuring your code it gives you the complete freedom to choose your own architecture based on your needs, how large or small your app is.

Collapse
 
thejaredwilcurt profile image
The Jared Wilcurt • Edited

I'm sorry friend, but literally every "pro" you mentioned here is true of all other JS Frameworks in 2025, and actually far more so in most cases. The problems with React are numerous and exclusive to it. You need to switch to ANYTHING else and then you will understand why React gets made fun of so much. The most impressive thing about React is, over the years, despite the landscape for JS frameworks changing so much, and React itself changing so much, it has somehow consistently been the worst option at all times. For different reasons, at different moments in time, but always, from a technical perspective, the worst choice. Are you afraid of trying something new? Then go with Solid.js, it's basically "React but it doesn't suck as much". Are you wanting some street cred? Go with Svelte. Do you want the objectively best option, because it stole all the best ideas from everyone else and did them better? Go with Vue. Do you want money? Even Angular is better than React, not by a lot, but it is. And those are just the big ones, there are so many more. Branch out, your future self will thank you. Don't be a React developer, don't even be a JavaScript developer, be a Software Developer.

Thread Thread
 
mohamed_kamel_cefecb4db25 profile image
Mohamed Kamel

You went for the assumption that i havent tried other tools which is weird.
Also saying i needed to branch out and be a software developer rather than being a react dev and blah blah .... just show you are full of yourself.

First of all I think you are missing the point here, i am not advicing or pushing anyone to swap tools like you strongly did , what i said is that naturally every thing in this world being a tech related or an objet has its goods and bads.

Giving a pro tip by saying to ppl to switch to some other tools is again and i am not gonna change my opinion is "horrendous advice".

I bet you know that reactjs can not be compared with vue and angular since its a library not a framework.
So the comparison thing you kept going about in your comment doesnt weigh to anything literally.
And if you dont know about this maybe you go read about reactjs and nextjs so next time you give a "PRO TIP" on a fair and objective basis rather than keep saying nonesense.

Preaching against reactjs is like saying those big companies like airbnb or booking dont understand business and that they should desperately hire you cause you and only will be able to put them on the right track :D

Collapse
 
daviddanielng profile image
David Daniel

These anti-react devs are from the same womb as rust Devs.

Thread Thread
 
thejaredwilcurt profile image
The Jared Wilcurt

There's a reason why we outsource so many React jobs overseas, but you never see Rust or Vue jobs get outsourced. It's because those are actual desirable jobs. No one wants to work with COBOL, FORTRAN, old PHP, or React.

Thread Thread
 
daviddanielng profile image
David Daniel

People outsource so many React jobs overseas, because it is cheaper.

If Vue or Rust is as popular, it would be out sourced.

You all have been saying PHP is dead for like 15 years. Yet it still powers a huge chuck of the web.

Collapse
 
vickerdent profile image
Vickerdent

Wanted to ask. Does Vue have something similar to react native for mobile and even desktop app development?

Collapse
 
thejaredwilcurt profile image
The Jared Wilcurt

Yes, NativeScript-Vue is a common choice. Tauri is popular if you use Rust. There is also "Vue-Native" which is a Vue wrapper around React-Native, it's not commonly recommended unless there is a specific React-Native library your app can't function without, or you are transitioning away from React-Native. There is also Ionic/Capacitor, much simpler if performance isn't a major requirement. And then Quasar if you need more than just Mobile. And of course, there's always the option of using a PWA which is pretty underrated, as many of the most common "native" features people want are available via this API now.

Collapse
 
b_maj_6cfdf9e36c5a12cf188 profile image
B Maj

Hard disagree. If React is too difficult for you it’s not because React is bad, your skill level likely isn’t where it needs to be. Level up.

Collapse
 
thejaredwilcurt profile image
The Jared Wilcurt

"Hey, you shouldn't use that gun, it doesn't have a safety and it always points at your foot". "HA! If you can't move your foot fast enough not to shoot it, it sounds like you have skill issues. Level up bro! (proceeds to shoot self in foot, then puts gold medal around his own neck and smiles while bleedning out)"

Collapse
 
zeeshanahmadkhalil profile image
Zeeshan Ahmad Khalil • Edited

VueJS is still second best option.

Collapse
 
thejaredwilcurt profile image
The Jared Wilcurt

You mean popular, not best. Read this next sentance as many times as it takes for you to understand and internalize it.

There is no correlation between quality and popularity.

Thread Thread
 
mohamed_kamel_cefecb4db25 profile image
Mohamed Kamel

Nah, its popular because it's simply the best whether you agree or not

Collapse
 
zeeshanahmadkhalil profile image
Zeeshan Ahmad Khalil

After React

Collapse
 
erickbgomez profile image
Erick B. Gómez

Very useful tips! I've been struggling this hook in my projects, specially for fetching data or syncing with another component states. Thank you for sharing these tips 🙌