Last active
December 16, 2018 16:14
-
-
Save productioncoder/a27f91612a1057e4c0554fbae1eca657 to your computer and use it in GitHub Desktop.
Fetching most popular videos in Home component
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
import Home from './containers/Home/Home'; | |
/* | |
Rest unchanged | |
*/ |
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
import React from 'react'; | |
import {connect} from "react-redux"; | |
import * as videoActions from "../../store/actions/video"; | |
import {bindActionCreators} from 'redux'; | |
import {getYoutubeLibraryLoaded} from '../../store/reducers/api'; | |
/* ... */ | |
class Home extends React.Component { | |
/* ... */ | |
componentDidMount() { | |
if (this.props.youtubeLibraryLoaded) { | |
this.props.fetchMostPopularVideos(); | |
} | |
} | |
componentDidUpdate(prevProps) { | |
if (this.props.youtubeLibraryLoaded !== prevProps.youtubeLibraryLoaded) { | |
this.props.fetchMostPopularVideos(); | |
} | |
} | |
} | |
function mapStateToProps(state) { | |
return { | |
youtubeLibraryLoaded: getYoutubeLibraryLoaded(state), | |
}; | |
} | |
function mapDispatchToProps(dispatch) { | |
const fetchMostPopularVideos = videoActions.mostPopular.request; | |
return bindActionCreators({fetchMostPopularVideos}, 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