create slice redux
import {createAction, createReducer} from '@reduxjs/toolkit ;
//Action
const add = createAction('add');
//Reducer
const Reducer = createReducer(initialState= 0, (builder)=>{
builder.addCase(add, (state,action) => state + 1)
})
4.33
3
function createSlice({
// A name, used in action types name: string,
// The initial state for the reducer
initialState: any,
// An object of "case reducers". Key names will be used to generate actions.
reducers: Object<string, ReducerFunction | ReducerAndPrepareObject>
// A "builder callback" function used to add more reducers, or
// an additional object of "case reducers", where the keys should be other
// action types
extraReducers?:
| Object<string, ReducerFunction>
| ((builder: ActionReducerMapBuilder<State>) => void)
})
Thank you!
3
0
Are there any code examples left?
New code examples in category Javascript