I have been working on an older code base with class components using Redux connect HOC. There are few RTK slices introduced before. I am abit confused as to why these 2 ways of using the action from the slice is working correctly (can see in Redux Toolkit that ways update the state and appear in the Actions panel (left hand side).
2 ways:
- with dispatch (updateAbc)
- without dispatch (updateXyz)
See example below
const mapDispatchToProps = (dispatch) => {
return {
updateAbc: (params) => dispatch(updateAbc(params)),
updateXyz,
}
}
Both are from the slice file:
const sampleSlice = createSlice({
name: 'sample',
initialState: {},
reducers: {
updateAbc: () => { /* do something */},
updateXyz: () => { /* do something */}
}
})
const { actions, reducer } = sampleSlice
export const {
updateAbc,
updateXyz,
} = actions
How come both are working or am I missing something or they are just both valid ways (but I don’t see how it dispatches it without the explicit call to dispatch)?