How to fix You must pass in a reducers object as the first argument to createSlice in React

ReactBEGINNERMEDIUMUpdated Dec 11, 2025ยท 89 views

This error occurs when using Redux Toolkit's createSlice function without providing a valid reducers object. The createSlice API requires a reducers configuration object to generate action creators and reducer logic automatically.

Quick fix

Fixes You must pass in a reducers object as the first argument to createSlice

import { createSlice } from '@reduxjs/toolkit';

const mySlice = createSlice({
  name: 'sliceName',
  initialState: { /* initial state */ },
  reducers: {
    // Your case reducer functions here
    increment: (state) => {
      state.value += 1;
    },
  },
});
  1. Verify the createSlice configuration object
  2. Check for empty reducers object
  3. Review imports and version compatibility
  4. Examine variable assignment and destructuring
react โ€” error
import { createSlice } from '@reduxjs/toolkit';
const mySlice = createSlice({
name: 'sliceName',
initialState: { /* initial state */ },
reducers: {
// Your case reducer functions here
increment: (state) => {
state.value += 1;
},
},
});
You must pass in a reducers object as the first argument to createSlice

What this error means

The createSlice function from Redux Toolkit is a utility that helps simplify Redux reducer and action creation. It expects a configuration object with a reducers field containing case reducer functions. When you call createSlice without passing a reducers object, or when the reducers argument is undefined or null, Redux Toolkit throws this error to indicate that the required configuration is missing.

Typical symptoms

  • Redux store setup fails during development
  • Console shows error: "You must pass in a reducers object as the first argument to createSlice"
  • Application crashes when trying to create a slice
  • Redux DevTools may not initialize properly

Common causes

  1. Forgetting to include the reducers property in the createSlice configuration object
  2. Passing an empty object {} without any reducer functions defined
  3. Accidentally passing undefined or null as the first argument
  4. Importing createSlice incorrectly or using a version mismatch
  5. Typographical errors in the configuration object (e.g., "reducer" instead of "reducers")

How to fix "You must pass in a reducers object as the first argument to createSlice"

1Verify the createSlice configuration object

Ensure you are passing an object with a reducers property to createSlice. The basic structure should look like:

javascript
import { createSlice } from '@reduxjs/toolkit';

const mySlice = createSlice({
  name: 'sliceName',
  initialState: { /* initial state */ },
  reducers: {
    // Your case reducer functions here
    increment: (state) => {
      state.value += 1;
    },
  },
});
2Check for empty reducers object

If you intentionally want a slice with no reducers (uncommon), you still need to provide an empty object:

javascript
const mySlice = createSlice({
  name: 'sliceName',
  initialState: {},
  reducers: {}, // Empty but present
});

However, typically you'll want to define at least one reducer function.

3Review imports and version compatibility

Make sure you are importing createSlice correctly:

javascript
// Correct import for Redux Toolkit
import { createSlice } from '@reduxjs/toolkit';

// Not from 'redux' or other packages

Also ensure your Redux Toolkit version is compatible with your usage. Check package.json for @reduxjs/toolkit version.

4Examine variable assignment and destructuring

If you are creating the configuration object dynamically, ensure the reducers property is correctly assigned:

javascript
// Example of dynamic creation (still needs reducers)
const sliceConfig = {
  name: 'mySlice',
  initialState,
  reducers: myReducers, // Make sure myReducers is defined and not undefined
};
const mySlice = createSlice(sliceConfig);
5Test with a minimal example

Create a minimal slice to isolate the issue:

javascript
import { createSlice } from '@reduxjs/toolkit';

const testSlice = createSlice({
  name: 'test',
  initialState: { value: 0 },
  reducers: {
    testAction: (state) => {
      state.value += 1;
    },
  },
});

console.log(testSlice.actions.testAction());

If this works, compare with your original code to find differences.

Advanced notes

The createSlice function internally uses createAction and createReducer. The reducers object is mandatory because it defines the action types and the corresponding state updates. If you need to respond to actions defined outside the slice (like thunks or other slices), use the extraReducers field instead. Note that extraReducers is optional and doesn't generate action creators, while reducers is required for generating slice-specific actions.

Frequently asked questions

What does "You must pass in a reducers object as the first argument to createSlic" mean?
The createSlice function from Redux Toolkit is a utility that helps simplify Redux reducer and action creation. It expects a configuration object with a reducers field containing case reducer functions. When you call createSlice without passing a reducers object, or when the reducers argument is undefined or null, Redux Toolkit throws this error to indicate that the required configuration is missing.
How do I fix "You must pass in a reducers object as the first argument to createSlic"?
This error occurs when using Redux Toolkit's createSlice function without providing a valid reducers object. The createSlice API requires a reducers configuration object to generate action creators and reducer logic automatically.
What causes "You must pass in a reducers object as the first argument to createSlic"?
Forgetting to include the reducers property in the createSlice configuration object Passing an empty object {} without any reducer functions defined Accidentally passing undefined or null as the first argument
Is the "You must pass in a reducers object as the first argument to createSlic" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading