I migrate my app from redux thunk to redux toolkit and while implementing one slice I got an error that says: Expected 0 arguments, but got 1.
This is my slice:
const toastNotificationSlice = createSlice({
name: 'toastNotification',
initialState,
reducers: {
showToastNotification(state, action) {
return { ...state, ...action.payload };
},
resetToastNotification() {
return initialState;
},
},
});
export const { showToastNotification, resetToastNotification } = toastNotificationSlice.actions;
export default toastNotificationSlice.reducer;
and this is where I do the dispatch:
useAppDispatch(showToastNotification({ severity: 'error', summary: 'Error', detail: 'Not authorized.' }));
What can be the problem here? Thanks in advance!
CodePudding user response:
What is this useAppDispatch? Usually this returns a dispatch method which then needs to be executed. So your execution should look like
useAppDispatch()(show....);
of course it is better to store the dispatch like
const dispatch = useAppDispatch();
...
dispatch(show...);
I do not know what is this useAppDispatch so it is only a guess