Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Redux store throws 'does not have a valid reducer'

ErrorStore does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.

Short answer

configureStore needs either one reducer function or an object whose values are reducer functions. The error appears when it gets something else: a whole slice instead of slice.reducer, an undefined import, an empty object, or a reducer that returns undefined. Log what you pass in, then fix the import or the return.

  • Applies to Redux Toolkit 2, Redux 5, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the reducer map right before configureStore. Every value must be a function, never undefined or an object.

    const reducer = { posts: postsReducer, users: usersReducer };
    console.log(Object.entries(reducer).map(([k, v]) => [k, typeof v]));
  2. 2Match what you see, then jump to its fix

    1. 1typeof prints 'undefined' or 'object' for one keyAn import is undefined, or you passed the slice instead of slice.reducerFix
    2. 2The call is configureStore({}) or reducer is not set, or the map is nested one level too deepThe reducer option is empty or has the wrong shapeFix
    3. 3A slice reducer written by hand has an early return, or no default caseA reducer returns undefinedFix

What does the error look like?

  • Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.

Cause 1 of 3

An import is undefined, or you passed the slice instead of slice.reducer

1Check

A slice file default-exports todosSlice.reducer. Importing with braces, or passing the slice object, gives undefined or an object.

grep -rn "export default" src/features/

2Fix

Export the reducer as the default and import it without braces, as in the Redux migration guide.

// postsSlice.js
export default postsSlice.reducer

// store.js
import postsReducer from '../features/posts/postsSlice'

3Verify

The log now shows 'function' for every key.

npm test

Confirmed by redux.js.org

Did this fix it?

Cause 2 of 3

The reducer option is empty or has the wrong shape

1Check

reducer accepts a single reducer function, or an object of slice reducers that configureStore passes to combineReducers.

grep -rn "configureStore" src/

2Fix

Give it a function, or a flat object of slice reducers.

const store = configureStore({
  reducer: { todos: todosReducer, visibility: visibilityReducer },
})

3Verify

Create the store and read its state.

console.log(store.getState())

Confirmed by redux.js.org

Did this fix it?

Cause 3 of 3

A reducer returns undefined

1Check

combineReducers throws when a reducer returns undefined, and it probes each reducer by passing undefined as state, even if preloadedState is set.

grep -rn "switch (action.type)" src/

2Fix

Give the state parameter a default and return state for unknown actions.

export default function counter(state = 0, action) {
  switch (action.type) {
    case 'INCREMENT':
      return state + 1
    default:
      return state
  }
}

3Verify

Run the store once; the error goes away.

console.log(counter(undefined, { type: '@@init' }))

Confirmed by redux.js.org

Did this fix it?

How do I stop it coming back?

  • Use createSlice and export slice.reducer as the default, so hand-written switch statements are rare.
  • Add one test that creates the store and checks getState() has every expected key.
  • Keep the reducer map flat: one key per slice.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.