I have an array and i'm dispatching LIKE_POST action from child component. Redux state updated but view not updating. I'm using Flatlist. And using extradata. (Working ADD_POST and DELETE_POST actions)
action.payload returning liked post id,
In reducer:
const initialState = {
feedData: [],
loading: false,
};
...
//FETCH FEED
...
case LIKE_POST:
return {
...state,
feedData: [
...state.feedData.map((post) => {
if (post.id === action.payload) {
return {
...post,
like: {
count: 1,
isLiked: true,
},
};
}
return post;
}),
],
};
Logger is returning like:1 and isLiked:true but view not updated.
useSelectororconnect) call you are using here as well. Also, in general you probably should follow the official recommendation to use redux toolkit instead of writing plain redux logic by hand, as in RTK reducers you can use mutating logic. Your code in that case would becomeconst found = state.feedData.find(post => post.id === action.payload); if (found) { found.like = {count: 1, isLiked: true } }- phry