CombineReducers from Redux Course

On the slide 4 - combining Reducers I have used the following reducer code:
import { combineReducers } from “redux”;

import bugsReducer from ‘./bugs’;

import projectsReducer from ‘./projects’;

export default combineReducers({

bugs: bugsReducer,

projects: projectsReducer

});

but in Index.js actions is not recognized. what is missing:
store.dispatch(bugAdded({ description: “Bug 1” }));

Here is the slice for the bugs:
import { createSlice} from “@reduxjs/toolkit”;

let lastId = 0;

const slice = createSlice({

name: "bugs",

initialState: [],

reducers: {

    bugAdded: (bugs, action) => {

        bugs.push({

       

            id: ++lastId,

            description: action.payload.description,

            resolved: false,

        });

    },

    bugResolved: (bugs, action) => {

                const index = bugs.findIndex(bug => bug.id === action.payload.id);

                bugs[index].resolved = true;

    },

    bugRemoved: (bugs, action) => {

       bugs.filter(bug => bug.id !== action.payload.id);

       

    }

}

});

export const { bugAdded, bugResolved, bugRemoved } = slice.actions;

export default slice.reducer;

I realized that I was missing the imports for bugs and projects reducer in index.js after that it worked here is index.js
import configureStore from “./store/configureStore”;

import { bugAdded, bugResolved, bugRemoved} from “./store/bugs”;

import{projectAdded} from “./store/projects”;

const store = configureStore();

store.subscribe(() => {

console.log(“Store changed!”, store.getState());

});

console.log(store);

store.dispatch(bugAdded({ description: “Bug 1” }));

store.dispatch(projectAdded({ name: “project1” }));

store.dispatch(bugResolved({id:1}));

store.dispatch(bugAdded({description :“Bug 2”}));

store.dispatch(bugRemoved({id:1}));

console.log(store.getState(), “current state”);

1 Like