Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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,,
nextPageToken: getSearchNextPageToken(state,,
export default connect(mapStateToProps, mapDispatchToProps)(Search);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment