ProNextJS

    Should I Use React-Query or useEffect/fetch?

    Jack HerringtonJack Herrington

    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.

    Subscribe for Free Tips, Tutorials, and Special Discounts

    We're in this together!

    I respect your privacy. Unsubscribe at any time.