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
 
keyr_syntax profile image
keyr Syntax

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
 
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
 
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 • Edited

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

If Vue or Rust is as popular, it will 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
 
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.

Collapse
 
elvissautet profile image
Elvis Sautet

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

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 🙌