createSlice()
↔ RTK API fn to setup slice state with input { initialState
, reducers
object, name
}
Source: redux
const initialState = {
value: 0
}
export const countSlice = createSlice({
name: "_name of slice to show under reduxDevTools only??",
initialState,
reducers: {
increment: (state) => state.value += 1,
decrement: (state) => state.value -= 1,
incrementByAmount: (state, action: PayloadAction<number\>) => state.value += action.payload
}
})
export const { increment, decrement, incrementByAmount } = countSlice.actions
export const selectCount = (state: RootState) => state.count.value
to export actions from slice
export const { actionType1, actionType2 } = _mySlice.actions
extraReducers
to allow createSlice()
to respond to other extenal type (action type not generated by itself)
References
extraReducers
↔ to allowcreateSlice()
to respond to other extenal type (action type not generated by itself)