Skip to content

Instantly share code, notes, and snippets.

@productioncoder productioncoder/Home.js
Last active Feb 28, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.