Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Youtube reducing fetchMostPopularVideos request
function reduceFetchMostPopularVideos(response, prevState) {
const videoMap = response.items.reduce((accumulator, video) => {
accumulator[] = 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,
return {
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.