JS Built-ins
redux-toolkitconfigureStorebeginner

Configure Store (Basic)

πŸ“– Usage Example
const { configureStore, createSlice } = ReduxToolkit
const slice = createSlice({ name: 'n', initialState: 0, reducers: { inc: s => s + 1 } })
const store = configureStore({ reducer: slice.reducer })
store.dispatch(slice.actions.inc())
store.getState() // β†’ 1

configureStore wraps the Redux createStore with defaults β€” pass your slice reducer directly.

Configure Store

configureStore creates a Redux store with sensible defaults (Redux DevTools, thunk middleware). Pass a reducer option with either a single reducer or an object of slice reducers.

Challenge: Create a counter slice and a store using it as the sole reducer.

store.getState()   // β†’ 0
store.dispatch(counterSlice.actions.inc())
store.getState()   // β†’ 1
πŸ’‘ Hints (3)
  • β€’ Pass `reducer: counterSlice.reducer` (the function itself, not `counterSlice`).
  • β€’ `store.dispatch(action)` sends an action to the store.
  • β€’ `store.getState()` retrieves the current state.