Redux Toolkit
yarn add react-redux @reduxjs/toolkitConfigure Store
const store = configureStore({
reducer: counter
})Create Slice
import { createSlice } from "@reduxjs/toolkit";
const counterSlice = createSlice({
name: "counter",
initialState: 0,
reducers: {
increment: (state) => state + 1,
decrement: (state) => state - 1,
//called when dispatch type counter/addTodo
addTodo(state, action) {
const { id, text } = action.payload;
state.push({ id, text, completed: false });
//allowed to mutuate because function wrapped with produce from Immer library
},
},
});
export const { increment, decrement, addTodo } = todosSlice.actions;
export default todosSlice.reducer;Old Helpers but unneeded b/c create Slice
Last updated