I want to add a post to an array of posts in the reducer. Normally I would just do this:
CREATE_NEW__POST_SUCCESS: {
return {
...state,
fetchingPosts: false,
error: null,
posts: [...state.posts, ...action.payload],
};
However my current project requires me to use Immutable.js With Immutable the state is set with .set() or .merge() or .update()
case CREATE_NEW_POST_SUCCESS: {
return state
.set('fetchingPosts', false)
.set('posts', action.payload)
.set('postsError', null);
This overwrites the whole array of posts with just one post object. I tried lots of things like
.set('posts' ,[...state.posts, ...action.payload])
But no joy