Home > Software engineering >  Problem with createActionThunk redux toolkit
Problem with createActionThunk redux toolkit

Time:09-27

Hello I made a createAsyncThunk function which is manipulating the actual state (it removes value with specific index). It executes but it doesn't update the firebase database and I'm not getting the value of categories array in the extraReducers. I don't know why because when I use console.log the categories array has got values. I'm using typescript and redux toolkit.

export const removeCategory = createAsyncThunk(
"categories/removeCategory",
async (index: number, thunkAPI) => {
    const state = thunkAPI.getState() as RootState;
    const categories = [...state.categories];
    categories.splice(index, 1);
    console.log(categories);

    const updates = { categories: [] as string[] };
    updates["categories"] = [...categories];
    update(ref(database), categories);
    return categories;
}
);

CodePudding user response:

In this part of the code, are you sure you don't want to send the updates object instead of the categories?

const updates = { categories: [] as string[] };
updates["categories"] = [...categories];
update(ref(database), updates);
return categories;
  • Related