Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Created November 16, 2018 19:01
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 productioncoder/085390d341d541a337592d3b4024b3ef to your computer and use it in GitHub Desktop.
Save productioncoder/085390d341d541a337592d3b4024b3ef to your computer and use it in GitHub Desktop.
Youtube in React: get comments for video id selector
import {createSelector} from 'reselect';
/* ... */
const getCommentIdsForVideo = (state, videoId) => {
const comment = state.comments.byVideo[videoId];
if (comment) {
return comment.ids;
}
return [];
};
export const getCommentsForVideo = createSelector(
getCommentIdsForVideo,
state => state.comments.byId,
(commentIds, allComments) => {
return commentIds.map(commentId => allComments[commentId]);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment