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;
}
);
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;
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.