Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Created November 22, 2018 18:30
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/91aab3ebe82aedefc1f9b677a1b96e98 to your computer and use it in GitHub Desktop.
Save productioncoder/91aab3ebe82aedefc1f9b677a1b96e98 to your computer and use it in GitHub Desktop.
Youtube in React: wiring up Search component to Redux state
/* ... */
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