Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Youtube reducing fetchMostPopularVideos request
function reduceFetchMostPopularVideos(response, prevState) {
const videoMap = response.items.reduce((accumulator, video) => {
accumulator[video.id] = video;
return accumulator;
}, {});
let items = Object.keys(videoMap);
if (response.hasOwnProperty('prevPageToken') && prevState.mostPopular) {
items = [...prevState.mostPopular.items, ...items];
}
const mostPopular = {
totalResults: response.pageInfo.totalResults,
nextPageToken: response.nextPageToken,
items,
};
return {
...prevState,
mostPopular,
byId: {...prevState.byId, ...videoMap},
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.