Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Last active October 28, 2018 13:55
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/fb3763ce76ede872f8d602f1fe9a50ab to your computer and use it in GitHub Desktop.
Save productioncoder/fb3763ce76ede872f8d602f1fe9a50ab to your computer and use it in GitHub Desktop.
Youtube get videos by category selector
export const getVideosByCategory = createSelector(
state => state.videos.byCategory,
state => state.videos.byId,
state => state.videos.categories,
(videosByCategory, videosById, categories) => {
return Object.keys(videosByCategory || {}).reduce((accumulator, categoryId) => {
const videoIds = videosByCategory[categoryId].items;
const categoryTitle = categories[categoryId];
accumulator[categoryTitle] = videoIds.map(videoId => videosById[videoId]);
return accumulator;
}, {});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment