Version: 0.0.1
Last Updated: Unknown
Use this template to create a Redux reducer.
| Variable | Data Type | Info |
|---|---|---|
name | string | The name of the reducer |
1import { createSlice, PayloadAction } from "@reduxjs/toolkit";2import type { Object } from "ts-toolbelt";34type <%= _.upperFirst(_.camelCase(name)) %> = {5 name: string6}78// Define the initial state using that type9const initialState = {};1011export const <%= _.camelCase(name) %>Slice = createSlice({12 name: "<%= _.camelCase(name) %>",13 // `createSlice` will infer the state type from the `initialState` argument14 initialState,15 // TODO: update example reducers16 reducers: {17 clearProject: () => ({}),18 // Use the PayloadAction type to declare the contents of `action.payload`19 setProject: (_state, action: PayloadAction<Object.Optional<<%= _.upperFirst(_.camelCase(name)) %>>>) =>20 action.payload,21 },22});2324export const { clearProject, setProject } = <%= _.camelCase(name) %>Slice.actions;2526// Other code such as selectors can use the imported `RootState` type27// export const select<%= _.upperFirst(_.camelCase(name)) %> = (state: RootState) => state.<%= _.camelCase(name) %>;2829export default <%= _.camelCase(name) %>Slice.reducer;