Last active
February 28, 2019 19:44
-
-
Save productioncoder/29b40925d48f15e0a35a6ddadc537180 to your computer and use it in GitHub Desktop.
Youtube fetch video categories
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
/* 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