JS Built-ins
redux-toolkitconfigureStoreintermediate

Configure Store with Multiple Slices

πŸ“– Usage Example
const store = configureStore({
  reducer: {
    counter: counterSlice.reducer,
    name: nameSlice.reducer,
  },
})
store.getState() // β†’ { counter: 0, name: '' }

Passing an object of reducers to configureStore automatically combines them β€” similar to combineReducers.

Configure Store with Multiple Slices

Pass an object of slice reducers to configureStore to build a combined state tree. Each key becomes a namespace in the state.

Challenge: Create a counter slice and a name slice, then combine them:

store.getState() // β†’ { counter: 0, name: '' }
πŸ’‘ Hints (3)
  • β€’ Pass `reducer: { counter: counterSlice.reducer, name: nameSlice.reducer }` to nest them.
  • β€’ Each slice only manages its own portion of state.
  • β€’ The state shape mirrors the keys you provide in the reducer object.