简体   繁体   中英

Redux Toolkit Expected 0 arguments, but got 1 error

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM