Last active
December 17, 2018 16:05
-
-
Save productioncoder/044baeb8e6dc628d6c8a3d044a628f09 to your computer and use it in GitHub Desktop.
Youtube Home component fetch most popular videos by category id
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
/*....*/ | |
class Home extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
categoryIndex: 0, | |
}; | |
} | |
componentDidUpdate(prevProps) { | |
if (this.props.youtubeLibraryLoaded !== prevProps.youtubeLibraryLoaded) { | |
this.fetchCategoriesAndMostPopularVideos(); | |
} else if (this.props.videoCategories !== prevProps.videoCategories) { | |
this.fetchVideosByCategory(); | |
} | |
} | |
fetchVideosByCategory() { | |
const categoryStartIndex = this.state.categoryIndex; | |
const categories = this.props.videoCategories.slice(categoryStartIndex, categoryStartIndex + 3); | |
this.props.fetchMostPopularVideosByCategory(categories); | |
this.setState(prevState => { | |
return { | |
categoryIndex: prevState.categoryIndex + 3, | |
}; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment