-1

I friends, I develop react redux toolkit slice everything ok but in function dispatch not working send to dispatchUserBlockingUpdate function in react-dom.development.js where is the my problem ?

I look changeProfitSortType function get data when need to send dispatch(changeProfitSort) not work !

This is: sortingSlice.js

import {createSlice} from "@reduxjs/toolkit";

export const sortingSlice = createSlice({
    name: 'sorting',
    initialState: {
        profitSortType: false,
    },
    reducers: {
        changeProfitSort: (state, action) => {
            state.profitSortType = action.payload;
            //return { ...state, profitSortType: action.payload }
        },
    },
});

export const { changeProfitSort } = sortingSlice.actions;

export const changeProfitSortType = (data) => async dispatch => {
    console.log(data);
    let status = data.status;
    console.log(status);
    await dispatch(changeProfitSort(status));
}

export default sortingSlice.reducer;
Linda Paiste
  • 38,446
  • 6
  • 64
  • 102

1 Answers1

0

Your sortingSlice is fine.

changeProfitSort is not an asynchronous function, so await dispatch(changeProfitSort(status)); doesn't make sense.

You don't need the changeProfitSortType function at all. You can just call dispatch(changeProfitSort(data.status)) in your component instead of dispatch(changeProfitSortType(data)).

If the data is coming from an asynchronous function then you might want to use createAsyncThunk.

Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
  • Thank you for answer, I changed my codes and I delet async and await. But anything changed already not work :( my new codes export const sortingSlice = createSlice({ name: 'sorting', initialState: { profitSortType: false, }, reducers: { changeProfitSort: (state, action) => { state.profitSortType = action.payload; }, }, }); export const { changeProfitSort } = sortingSlice.actions; export const changeProfitSortType = (data) => dispatch => { dispatch(changeProfitSort(data)); } – NikolayAndrv May 25 '21 at 00:09