What Redux Does
- Single source of truth — one global state tree
- State is read-only — updated via dispatched actions
- Pure reducers —
(state, action) => newState - DevTools — time-travel debugging
- Middleware — thunks, sagas, listeners for side-effects
- RTK Query — server state with caching (alternative to React Query)
- createSlice — auto-generate actions + reducers
- Immer — write mutating code, RTK converts to immutable
Architecture
Dispatched action → reducer(s) → new state → subscribers rerender. Store holds state, useSelector subscribes, useDispatch sends actions. Middleware intercepts actions for async work.
Self-Hosting
Client library only.
Key Features
- Redux DevTools browser extension
- Time-travel debugging
- RTK Query (server state)
- createSlice / createAsyncThunk
- Listener middleware
- TypeScript-first
- React, Vue, Angular, Svelte bindings
- SSR-compatible
Comparison
| Library | Boilerplate | DevTools | Server State | Size |
|---|---|---|---|---|
| Redux Toolkit | Low | Best | RTK Query | ~13KB |
| Zustand | Minimal | Redux DevTools | No | ~1KB |
| Jotai | Atomic | Yes | Via suspense | ~3KB |
| Valtio | Minimal | Yes | No | ~3KB |
| MobX | Reactive | Yes | No | ~15KB |
常见问题 FAQ
Q: Redux 过时了吗? A: 没有。用 RTK 写的 Redux 代码量和 Zustand 差不多,但保留了 DevTools 时间旅行和大规模可维护性。
Q: RTK Query vs React Query? A: 功能重叠。RTK Query 更贴近 Redux 生态,共享 store;React Query 更轻,API 更简洁。
Q: 何时用 Redux vs Zustand? A: 超大应用、严格架构、跨团队协作 → Redux。小中型、追求简洁 → Zustand。
来源与致谢 Sources
- Docs: https://redux.js.org
- RTK: https://redux-toolkit.js.org
- GitHub: https://github.com/reduxjs/redux
- License: MIT