sliceReducer (index)
Mon Apr 25 2022 11:31:19 GMT+0000 (Coordinated Universal Time)
Saved by
@nimaSm
import { createSlice } from "@reduxjs/toolkit";
import { actionName } from "actionName-file-path"
export const sliceName = createSlice({
name: "any-name",
initialState: {
// all initial states
},
reducers: {
// all reducers defined here
reducerName(state, action){
// reducer logic
}
},
extraReducers: {
// all async extra reducers defined here
[actionName.pending]: (state, action) => {
// action object come from actionName
// const { response, data, params} = action.payload
},
[actionName.fulfilled]: (state, action) => {},
[actionName.rejected]: (state, action) => {},
}
})
export const { reducerName } = sliceName.actions; // import them in any components needed
export default sliceName.reducer; // import it in rootRedcer (allReducers)
content_copyCOPY
Comments