HomeReact
Chapter 15
15 β Redux Toolkit (RTK)
Redux Toolkit is the official, recommended way to write Redux. It eliminates boilerplate and includes best practices by default.
Core Concepts
| Concept | Description |
|---|---|
| Store | Single source of truth for global state |
| Slice | A piece of state + its reducers (auto-generates action creators) |
| Action | An object describing what happened { type, payload } |
| Reducer | Pure function that updates state based on action |
| Dispatch | Send an action to the store |
| Selector | Extract data from the store |
| Thunk | Async logic (API calls, side effects) |
RTK vs Classic Redux
| Classic Redux | Redux Toolkit |
|---|---|
switch statements | createSlice (auto-generates) |
| Manual action creators | Auto-generated from slice |
| Immutable updates by hand | Uses Immer under the hood |
| Separate files for actions/reducers | Everything in one slice |
| Manual thunk setup | createAsyncThunk built-in |
File
redux-toolkit.tsxβ configureStore, createSlice, createAsyncThunk, RTK Query basics, typed hooks, selectors