Answers for "create slice redux"

0

redux toolkit reducer

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)
})
Posted by: Guest on October-31-2020
0

create slice redux

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)
})
Posted by: Guest on July-29-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language