Created
November 9, 2018 20:09
-
-
Save productioncoder/bc557455effcb79c174da68d1d0ddf4c to your computer and use it in GitHub Desktop.
Youtube in React: video details and related videos
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
function reduceWatchDetails(responses, prevState) { | |
const videoDetailResponse = responses.find(r => r.result.kind === VIDEO_LIST_RESPONSE); | |
// we know that items will only have one element | |
// because we explicitly asked for a video with a specific id | |
const video = videoDetailResponse.result.items[0]; | |
const relatedEntry = reduceRelatedVideosRequest(responses); | |
return { | |
...prevState, | |
byId: { | |
...prevState.byId, | |
[video.id]: video | |
}, | |
related: { | |
...prevState.related, | |
[video.id]: relatedEntry | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment