Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Last active February 28, 2019 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save productioncoder/29b40925d48f15e0a35a6ddadc537180 to your computer and use it in GitHub Desktop.
Save productioncoder/29b40925d48f15e0a35a6ddadc537180 to your computer and use it in GitHub Desktop.
Youtube fetch video categories
/* imports unchanged */
class Home extends React.Component {
render() {
/* ... */
}
componentDidMount() {
if (this.props.youtubeLibraryLoaded) {
this.fetchCategoriesAndMostPopularVideos();
}
}
componentDidUpdate(prevProps) {
if (this.props.youtubeLibraryLoaded !== prevProps.youtubeLibraryLoaded) {
this.fetchCategoriesAndMostPopularVideos();
}
}
fetchCategoriesAndMostPopularVideos() {
this.props.fetchMostPopularVideos();
this.props.fetchVideoCategories();
}
}
function mapStateToProps(state) { /* ... */ }
function mapDispatchToProps(dispatch) {
const fetchMostPopularVideos = videoActions.mostPopular.request;
const fetchVideoCategories = videoActions.categories.request;
return bindActionCreators({fetchMostPopularVideos, fetchVideoCategories}, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(Home);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment