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

ConceptDescription
StoreSingle source of truth for global state
SliceA piece of state + its reducers (auto-generates action creators)
ActionAn object describing what happened { type, payload }
ReducerPure function that updates state based on action
DispatchSend an action to the store
SelectorExtract data from the store
ThunkAsync logic (API calls, side effects)

RTK vs Classic Redux

Classic ReduxRedux Toolkit
switch statementscreateSlice (auto-generates)
Manual action creatorsAuto-generated from slice
Immutable updates by handUses Immer under the hood
Separate files for actions/reducersEverything in one slice
Manual thunk setupcreateAsyncThunk built-in

File

  • redux-toolkit.tsx β€” configureStore, createSlice, createAsyncThunk, RTK Query basics, typed hooks, selectors