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;