i am using redux toolkit for my project i have a problem i access the state inside a reducer using current function provided by reduxjs
but when i update the state it is not updating i don’t know why i did a lot of research on that but i didn’t find anything useful here is my reducer
import { createSlice,current } from "@reduxjs/toolkit";
const initialState = {
posts: [],
};
const postSlice = createSlice({
name: "posts",
initialState,
reducers: {
updatePosts: (state, action) => {
const postsArray = Object.values(action.payload);
// state.posts = state.posts.concat(Object.values(action.payload));
state.posts.push(...postsArray);
},
updateLikes: (state, action) => {
const { postId, userId } = action.payload;
const currentState = current(state.posts)
},
},
});
export const { updatePosts, updateLikes } = postSlice.actions;
export default postSlice.reducer;
inside updateLikes i am getting postId, and userId which i am getting successfully when i use dispatch. but when i get the current state using current function it also return me the state but when i try to push or remove anything from array nothing happen doesn’t show any error or anything else
Amir Mansoor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.