Skip to content

Instantly share code, notes, and snippets.

@productioncoder productioncoder/Home.js
Last active Dec 17, 2018

Embed
What would you like to do?
Youtube Home component fetch most popular videos by category id
/*....*/
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
You can’t perform that action at this time.