Both Redux and Zustand are tools that help manage data (state) in React applications, similar to having a central storage place for all your app's information. Redux is the older, more established option with strict rules and more setup required, while Zustand is newer, simpler, and easier to learn. These tools are often compared because developers need to choose between Redux's robust but complex approach and Zustand's modern, lightweight solution.
Redux is a predictable, container-based state management system, while Zustand is a small, fast, and scalable state management solution. Redux has a steeper learning curve due to its complex architecture, whereas Zustand is more straightforward and easy to use.
Both Redux and Zustand have excellent TypeScript support, with Redux having more extensive type definitions.
Both packages are compatible with all modern browsers, including Internet Explorer 11.
Redux has no dependencies, while Zustand depends on the 'immer' package for immutable state updates.
Zustand is generally faster and more lightweight than Redux due to its simpler architecture.
Both packages are compatible with popular frameworks like React, Angular, and Vue.js.
Redux has a larger and more active community, with more contributors and issues resolved.
Redux has more extensive and detailed documentation, while Zustand's documentation is more concise and easy to understand.
Redux is maintained by the React team, while Zustand is maintained by a smaller team of developers.
1import { createStore } from 'redux';
2const store = createStore((state = 0, action) => {
3 switch (action.type) {
4 case 'INCREMENT':
5 return state + 1;
6 default:
7 return state;
8 }
9});
This example creates a basic Redux store that increments a counter when an 'INCREMENT' action is dispatched.
1import create from 'zustand';
2const useStore = create((set) => ({
3 count: 0,
4 increment: () => set({ count: (state) => state.count + 1 }),
5}));
This example creates a basic Zustand store that increments a counter when the 'increment' function is called.
Choose Zustand for smaller applications or when simplicity and speed are crucial, and choose Redux for larger, more complex applications that require a more robust state management system.
A simple state management library that makes it easy to manage application data. It uses observable patterns to automatically update your app when data changes, making it less complicated than Redux.
Great for beginners because it requires less code than Redux and feels more like writing normal JavaScript. You don't need to write actions or reducers - just create stores and update them directly.
State ManagementA proxy-based state management tool that lets you write state updates like normal JavaScript. It makes your objects reactive automatically.
Similar to Zustand but even simpler to use. Perfect for developers who want their state management to feel like regular JavaScript objects.
State ManagementA tiny state management library inspired by Recoil. It uses atomic patterns but with a much smaller package size and simpler API.
Great alternative when you want atomic state management but don't need all of Recoil's features. It's super lightweight and easy to learn.
State ManagementFacebook's state management library built specifically for React. It uses a concept called atoms (pieces of state) and selectors (pieces that depend on atoms) to manage data flow.
Perfect for React developers who want something simpler than Redux but more powerful than useState. It's particularly good at handling complex state relationships and async data.
State ManagementA state management library based on state machines. It helps manage complex state logic and transitions in a visual and structured way.
Great for apps with complex state flows and business logic. While different from Redux/Zustand, it's excellent for managing application state that follows specific patterns or rules.
State ManagementRedux is a predictable state container for JavaScript apps.
It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. On top of that, it provides a great developer experience, such as live code editing combined with a time traveling debugger.
You can use Redux together with React, or with any other view library. The Redux core is tiny (2kB, including dependencies), and has a rich ecosystem of addons.
Redux Toolkit is our official recommended approach for writing Redux logic. It wraps around the Redux core, and contains packages and functions that we think are essential for building a Redux app. Redux Toolkit builds in our suggested best practices, simplifies most Redux tasks, prevents common mistakes, and makes it easier to write Redux applications.
The recommended way to start new apps with React and Redux Toolkit is by using our official Redux Toolkit + TS template for Vite, or by creating a new Next.js project using Next's with-redux
template.
Both of these already have Redux Toolkit and React-Redux configured appropriately for that build tool, and come with a small example app that demonstrates how to use several of Redux Toolkit's features.
# Vite with our Redux+TS template # (using the `degit` tool to clone and extract the template) npx degit reduxjs/redux-templates/packages/vite-template-redux my-app # Next.js using the `with-redux` template npx create-next-app --example with-redux my-app
We do not currently have official React Native templates, but recommend these templates for standard React Native and for Expo:
npm install @reduxjs/toolkit react-redux
For the Redux core library by itself:
npm install redux
For more details, see the Installation docs page.
The Redux core docs are located at https://redux.js.org, and include the full Redux tutorials, as well usage guides on general Redux patterns:
The Redux Toolkit docs are available at https://redux-toolkit.js.org, including API references and usage guides for all of the APIs included in Redux Toolkit.
The Redux Essentials tutorial is a "top-down" tutorial that teaches "how to use Redux the right way", using our latest recommended APIs and best practices. We recommend starting there.
The Redux Fundamentals tutorial is a "bottom-up" tutorial that teaches "how Redux works" from first principles and without any abstractions, and why standard Redux usage patterns exist.
The #redux channel of the Reactiflux Discord community is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - please come and join us there!
Redux is a valuable tool for organizing your state, but you should also consider whether it's appropriate for your situation. Please don't use Redux just because someone said you should - instead, please take some time to understand the potential benefits and tradeoffs of using it.
Here are some suggestions on when it makes sense to use Redux:
Yes, these guidelines are subjective and vague, but this is for a good reason. The point at which you should integrate Redux into your application is different for every user and different for every application.
For more thoughts on how Redux is meant to be used, please see:<br>
The whole global state of your app is stored in an object tree inside a single store. The only way to change the state tree is to create an action, an object describing what happened, and dispatch it to the store. To specify how state gets updated in response to an action, you write pure reducer functions that calculate a new state based on the old state and the action.
Redux Toolkit simplifies the process of writing Redux logic and setting up the store. With Redux Toolkit, the basic app logic looks like:
import { createSlice, configureStore } from '@reduxjs/toolkit' const counterSlice = createSlice({ name: 'counter', initialState: { value: 0 }, reducers: { incremented: state => { // Redux Toolkit allows us to write "mutating" logic in reducers. It // doesn't actually mutate the state because it uses the Immer library, // which detects changes to a "draft state" and produces a brand new // immutable state based off those changes state.value += 1 }, decremented: state => { state.value -= 1 } } }) export const { incremented, decremented } = counterSlice.actions const store = configureStore({ reducer: counterSlice.reducer }) // Can still subscribe to the store store.subscribe(() => console.log(store.getState())) // Still pass action objects to `dispatch`, but they're created for us store.dispatch(incremented()) // {value: 1} store.dispatch(incremented()) // {value: 2} store.dispatch(decremented()) // {value: 1}
Redux Toolkit allows us to write shorter logic that's easier to read, while still following the original core Redux behavior and data flow.
You can find the official logo on GitHub.
This project adheres to Semantic Versioning. Every release, along with the migration instructions, is documented on the GitHub Releases page.
Respectfully opinionated convention-driven framework for building React applications. Built on React, Webpack, Redux, and React Router.
Data portal API and component generation
Code recipes for Amber Framework
Pola pomoże Ci odnaleźć polskie wyroby. Zabierając Polę na zakupy odnajdujesz produkty “z duszą” i wspierasz polską gospodarkę.
This project is an educational exercise focused on cloning certain aspects of Airbnb. It is intended for educational purposes only.
Front-end infrastructure tool, base react, support webpack/vite/rspack.
Social media video sharing based (using Next.js, TypeScript, GoogleAuth, Sanity and CSS with Tailwind)