Created
November 22, 2018 18:30
-
-
Save productioncoder/91aab3ebe82aedefc1f9b677a1b96e98 to your computer and use it in GitHub Desktop.
Youtube in React: wiring up Search component to Redux state
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 {getYoutubeLibraryLoaded} from '../../store/reducers/api'; | |
import {getSearchNextPageToken, getSearchResults} from '../../store/reducers/search'; | |
import * as searchActions from '../../store/actions/search'; | |
import {bindActionCreators} from 'redux'; | |
import {connect} from 'react-redux'; | |
class Search extends React.Component { | |
/* ... */ | |
} | |
function mapDispatchToProps(dispatch) { | |
const searchForVideos = searchActions.forVideos.request; | |
return bindActionCreators({searchForVideos}, dispatch); | |
} | |
function mapStateToProps(state, props) { | |
return { | |
youtubeApiLoaded: getYoutubeLibraryLoaded(state), | |
searchResults: getSearchResults(state, props.location.search), | |
nextPageToken: getSearchNextPageToken(state, props.location.search), | |
} | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(Search); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment