Skip to content

Instantly share code, notes, and snippets.

@zrod
Created December 2, 2017 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zrod/a1dabd27d3c2d52d155971beada17864 to your computer and use it in GitHub Desktop.
Save zrod/a1dabd27d3c2d52d155971beada17864 to your computer and use it in GitHub Desktop.
spread operator mess
import authType from './authType';
import { LIKE_POST_SUCCESS } from '../actions/actionTypes';
export default function authReducer(state = authType, action) {
switch (action.type) {
// ...
case types.LIKE_POST_SUCCESS:
return {
...state,
...{
user: {
...state.user,
activity: {
...state.user.activity,
post: {
...state.user.activity.post,
likes: [
...state.user.activity.post.likes,
action.payload
]
}
}
}
}
};
default:
return state;
}
}
/**
* Part of the auth object:
{
user: {
id: 0,
username: '',
avatar: '',
activity: {
post: {
likes: [],
favorites: []
}
}
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment