Subscribe for Free Tips, Tutorials, and Special Discounts
We're in this together!
We respect your privacy. Unsubscribe at any time.
Question: Should I use react-query or useEffect/fetch?
Answer: I would strongly advise using a query handling library like react-query or SWR to manage client side fetching instead of writing your own code using useState, useEffect and fetch directly.
My reasoning is that these libraries handle all the error cases, queries and mutations, re-fetching, caching, request sharing between components, all that.
They are also small (SWR is slightly smaller though it does less) and considered "industry standard" for React applications.
Another great thing about these libraries is that they can be used to manage any returned promise. So that means that you can use them not just with fetch
but any other browser API that returns a promise.
Share this article with your friends
Written by Jack Herrington
Jack Herrington is a Full Stack Principal Engineer who orchestrated the rollout of React/NextJS at Walmart Labs and Nike. He is also the "Blue Collar Coder" on YouTube where he posts weekly videos on advanced use of React and NextJS as well as other frontend technologies trends. His YouTube channel hosts an entire free courses on React and TypeScript. He has written seven books including most recently No-BS TypeScript which is a companion book to the YouTube course.