Human Slice (Solution)
import { createSlice, nanoid } from "@reduxjs/toolkit";
const createHuman = (name) => ({
id: nanoid(),
name,
taskIds: [],
});
const initialState = [createHuman("Steve"), createHuman("Wes")];
export const humansSlice = createSlice({
name: "humans",
initialState,
reducers: {
add: (state, action) => {
const human = createHuman(action.payload);
state.push(human);
},
},
});
Now, we can add that to our store.
import { configureStore } from "@reduxjs/toolkit";
import { humansSlice } from "./humansSlice";
import { tasksSlice } from "./tasksSlice";
export const store = configureStore({
reducer: {
tasks: tasksSlice.reducer,
humans: humansSlice.reducer,
},
});