Jan 6, 2023
Power Up Your React Code With These Tools
This article compares the features and functionalities of React Query, Zustand, and Valtio.
Author


Book a call
Table of Contents
- Look at each of these libraries and compare their features and functionality
- Discuss how, when, and why you might want to use each one in your React projects
So, let's get started!
What Is React Query / SWR?
Benefits Of React Query
useEffect hook to retrieve data from the API within the component. useQuery hook. Also, the stale time for prefetching is 0.Example
To access the cached data, first, wrap your parent component using a QueryClientProvider. then provide queryClientProvider the query client.

Create a fetcher function that will be used to transfer data from the react-query to the useQuery hook as shown below. I used axios to get the data from the API, but you could write a standard function.

You must now call this hook within the functional component to specify the component's state, if the data is available, loaded, or if there is an issue obtaining the data. By using queryhook, we can analyze the other state's return.

SWR is an alternative to the React query library. However, it is primarily used with the NextJS framework, yet both perform comparable functions and have similar hooks.
What Is Zustand?
Redux, which allows you to create a custom hook to access and modify the data globally. It is a unidirectional data manager, which means data goes one way to mutate the store.Benefits of Zustand
- Zustand is a lightweight, zero-dependency library that is easy to start. It only requires a single function to create a store, and actions can be dispatched directly from the store itself.
- It uses a memoization technique called "shallow equals" to optimize performance. This means that it only re-renders components that depend on specific pieces of state.
- Zustand allows you to customize the store by adding middleware, getters, and other advanced features. This can be useful for adding additional functionality and handling async tasks.
- Zustand's
setStatefunction can also be used to update the state of the store, and the changes will automatically be reflected in your components. This can help you make your code more predictable and easier to debug.
Example
To create a custom hook, first, we need to create a store where we can define the initial state of the store.

Now, we can set the community array inside a component by calling the useCommunities hook, which will mutate our communities’ array inside our store globally.

Next, you need to access that data by calling the use communities hook.

What Is Valtio?
Benefits Of Using Valtio
- Valtio has a minimal API that is easy to understand and use. It only requires a single function to create a store, and actions can be dispatched using a simple dispatch function. This makes it easy to get started with Valtio and integrate it into your React app.
- It also uses a memoization technique called "shallow equals" to optimize performance. This means that Valtio only re-renders components that are dependent on specific pieces of state
- Valtio allows you to customize the store by adding middleware and other advanced features.
Example

Then, all you'll need to do is subscribe to and gain access to these communities inside a component using the useSnapshot hook. Remember that the useSnapshot should be used since it is in charge of re-rendering the components whenever the state changes. Alternatively, you can use the useProxy hook, which will only re-render our component when the part of the state that it is accessing has changed.


Useful Links
Subscribe to Our Newsletter
Subscribe to RSS
Press & Media Hub RSS FeedRelated Articles.
More from the engineering frontline.
Dive deep into our research and insights on design, development, and the impact of various trends to businesses.

Jun 30, 2026
Industry 4.0 Built Visibility. Industry 5.0 Must Automate Decisions, Says GeekyAnts CEO at ET Now Business Conclave 2026

Jun 27, 2026
Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability

Jun 26, 2026