Skip to content

Instantly share code, notes, and snippets.

@productioncoder productioncoder/search.js
Last active Nov 24, 2018

Embed
What would you like to do?
Youtube in React: search for videos reducer
function reduceSearchForVideos(response, searchQuery, prevState) {
let searchResults = response.items.map(item => ({...item, id: item.id.videoId}));
if (prevState.query === searchQuery) {
const prevResults = prevState.results || [];
searchResults = prevResults.concat(searchResults);
}
return {
totalResults: response.pageInfo.totalResults,
nextPageToken: response.nextPageToken,
query: searchQuery,
results: searchResults
};
}
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.