Last active
November 24, 2018 14:06
-
-
Save productioncoder/6a4427faa4153e5266e15840ea488814 to your computer and use it in GitHub Desktop.
Youtube in React: search for videos reducer
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 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