Redux is a predictable state container built around three ideas:
- Application state lives in a store.
- State changes are described by actions.
- Reducers compute the next state without mutating the previous state.
The original createStore API still explains the mechanics, although modern Redux applications should normally use Redux Toolkit.
The reducer
1 | const initialState = { |
A reducer must be deterministic and free of side effects. Given the same state and action, it should return the same next state. Network calls, timers, random values, and localStorage belong outside it.
Store mechanics
1 | import { legacy_createStore as createStore } from 'redux'; |
dispatch sends an action, the reducer computes new state, and subscribers are notified. Redux itself does not render HTML; UI bindings such as React Redux connect store updates to components.
Modern Redux Toolkit
1 | import { configureStore, createSlice } from '@reduxjs/toolkit'; |
The reducer appears to mutate state, but Redux Toolkit uses Immer to produce an immutable result safely.
When Redux is worth it
Use Redux when state is shared widely, transitions need strong conventions, or debugging and middleware justify the extra abstraction. Local component state does not need a global parliament. Start with the simplest ownership model and add Redux when coordination becomes the actual problem.