Back to home

redux-toolkit/

redux-reducer

Version: 0.0.1

Last Updated: Unknown


Redux Reducer

Use this template to create a Redux reducer.

Required

VariableData TypeInfo
namestringThe name of the reducer

Module files

1import { createSlice, PayloadAction } from "@reduxjs/toolkit";
2import type { Object } from "ts-toolbelt";
3
4type <%= _.upperFirst(_.camelCase(name)) %> = {
5 name: string
6}
7
8// Define the initial state using that type
9const initialState = {};
10
11export const <%= _.camelCase(name) %>Slice = createSlice({
12 name: "<%= _.camelCase(name) %>",
13 // `createSlice` will infer the state type from the `initialState` argument
14 initialState,
15 // TODO: update example reducers
16 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});
23
24export const { clearProject, setProject } = <%= _.camelCase(name) %>Slice.actions;
25
26// Other code such as selectors can use the imported `RootState` type
27// export const select<%= _.upperFirst(_.camelCase(name)) %> = (state: RootState) => state.<%= _.camelCase(name) %>;
28
29export default <%= _.camelCase(name) %>Slice.reducer;

Install


Lift generate


Repository

https://github.com/okeeffed/pkg-lift-redux-toolkit

Sections