Skip to content

Instantly share code, notes, and snippets.

@novonimo
Created November 13, 2019 08:07
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 novonimo/58dc7355fca8b9447a7666ca29bc5a78 to your computer and use it in GitHub Desktop.
Save novonimo/58dc7355fca8b9447a7666ca29bc5a78 to your computer and use it in GitHub Desktop.
reducerSnippet
case VOTE_COMMENT_SUCCESS:
return {
...state,
comments: state.comments.map(comment =>
comment.id === action.id
? {
...comment,
cached_votes_up: action.data.vote_up,
cached_votes_down: action.data.vote_down,
}
: comment.children[0]?.id === action.id
? {
...comment,
children: [
{
...comment.children[0],
cached_votes_up: action.data.vote_up,
cached_votes_down: action.data.vote_down,
},
],
}
: comment
),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment