Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Created November 9, 2018 20:09
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/bc557455effcb79c174da68d1d0ddf4c to your computer and use it in GitHub Desktop.
Save productioncoder/bc557455effcb79c174da68d1d0ddf4c to your computer and use it in GitHub Desktop.
Youtube in React: video details and related videos
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