Last active
November 10, 2018 11:24
-
-
Save productioncoder/f2c76a85b4cf45bcb1dbbfdf58fdd493 to your computer and use it in GitHub Desktop.
Youtube in React: related videos selector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getRelatedVideoIds = (state, videoId) => { | |
const related = state.videos.related[videoId]; | |
return related ? related.items : []; | |
}; | |
export const getRelatedVideos = createSelector( | |
getRelatedVideoIds, | |
state => state.videos.byId, | |
(relatedVideoIds, videos) => { | |
if (relatedVideoIds) { | |
// filter kicks out null values we might have | |
return relatedVideoIds.map(videoId => videos[videoId]).filter(video => video); | |
} | |
return []; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment