redux
Redux is a predictable state container for JavaScript applications, most commonly used with React but compatible with any UI framework. Redux centralizes applic…
Installation
npm install @reduxjs/toolkit react-redux
yarn add @reduxjs/toolkit react-redux
pnpm add @reduxjs/toolkit react-redux
Import
import { configureStore, createSlice } from '@reduxjs/toolkit';Quick Example
import { configureStore, createSlice } from '@reduxjs/toolkit';
const counterSlice = createSlice({
name: 'counter',
initialState: { value: 0 },
reducers: {
increment: (state) => { state.value += 1; },
decrement: (state) => { state.value -= 1; },
},
});
const store = configureStore({ reducer: { counter: counterSlice.reducer } });About redux
Redux is a predictable state container for JavaScript applications, most commonly used with React but compatible with any UI framework. Redux centralizes application state in a single store, with state changes described as plain action objects dispatched to pure reducer functions that compute the new state. This architecture provides predictability (same actions always produce same state), debuggability (time-travel debugging, action logging), and testability (reducers are pure functions). Redux Toolkit (RTK), the official recommended approach, simplifies Redux development dramatically with createSlice for defining reducers with Immer-powered immutable updates, createAsyncThunk for handling async operations, RTK Query for data fetching and caching, and configureStore for automatic middleware setup. RTK Query eliminates most hand-written data fetching logic by generating hooks like useGetUsersQuery() from API endpoint definitions. The Redux DevTools browser extension provides time-travel debugging, action inspection, state diffing, and action replay. While newer state management libraries like Zustand offer simpler APIs for many use cases, Redux remains dominant in large enterprise applications where strict unidirectional data flow, comprehensive DevTools, and the ability to serialize and replay entire application state provide clear architectural benefits.
Quick Facts
| Package | redux |
| Category | State Management |
| Weekly Downloads | 10M+ |
| License | MIT |
| Install | npm install @reduxjs/toolkit react-redux |
Related Packages
Zustand is a small, fast, and scalable state management library for React that provides a simple hoo…
MobX is a battle-tested state management library that makes state management simple and scalable thr…
React is the most popular JavaScript library for building user interfaces, developed and maintained …
Jotai is a primitive and flexible state management library for React that takes an atomic approach i…
XState is a state management and orchestration library that uses finite state machines and statechar…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.