Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the main difference between React Query and Redux?

currently I am using redux in different projects for state management. A few days back, I listened about react-query which is also used for state management and provides caching and async fetching. I am trying to figure out the main difference between these two libraries. Where I should use react-query and in which cases I need redux.

like image 892
Sanan Ali Avatar asked Jul 26 '21 06:07

Sanan Ali


People also ask

Is React query alternative to Redux?

React Query is a server-state library, responsible for managing asynchronous operations between your server and client. Redux, MobX, Zustand, etc. are client-state libraries that can be used to store asynchronous data, albeit inefficiently when compared to a tool like React Query.

Can I use React query and Redux together?

Have you ever wanted to use Redux with features like React Query provides? Now you can, by using Redux Toolkit and its latest addition: RTK Query. RTK Query is an advanced data-fetching and client-side caching tool.

What is difference between React and Redux?

Redux can be used with React. both are independent of each other. Redux is a state managing library used in JavaScript apps. It simply manages the state of your application or in other words, it is used to manage the data of the application.

What is React query used for?

React Query is often described as the missing data-fetching library for React. Still, in more technical terms, it makes fetching, caching, synchronizing, and updating server state in your React applications a breeze.


1 Answers

React-query is what you would call a specialized library. It holds an api cache for you - nothing else. And since it is specialized, it does that job quite well and requires less code.

Redux on the other hand gives you tools to just about store anything - but you have to write the logic. So you can do a lot more in Redux, but you'll have to potentialy write code that would not be necessary with a specialized library.

You can use them both side-by-side: api cache in react query, rest of your global state in Redux.

That said, the official Redux Toolkit also ships with an api cache abstraction RTK Query since version 1.6 with a similar feature set as React Query, but some different concepts overall - you might also want to check that out.

like image 117
phry Avatar answered Sep 28 '22 13:09

phry