📦
State Management10M+/wkMIT

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
npm install @reduxjs/toolkit react-redux
yarn
yarn add @reduxjs/toolkit react-redux
pnpm
pnpm add @reduxjs/toolkit react-redux

Import

ESM
import { configureStore, createSlice } from '@reduxjs/toolkit';

Quick Example

usage
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

Packageredux
CategoryState Management
Weekly Downloads10M+
LicenseMIT
Installnpm install @reduxjs/toolkit react-redux

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.