Skip to content

Instantly share code, notes, and snippets.

@productioncoder productioncoder/Watch.js
Last active Nov 17, 2018

Embed
What would you like to do?
Youtube in React: fetching more comments when hitting the bottom of the page
import * as commentActions from '../../store/actions/comment';
export class Watch extends React.Component {
render() {
const videoId = this.getVideoId();
return (
<WatchContent videoId={videoId}
channelId={this.props.channelId}
bottomReachedCallback={this.fetchMoreComments}
nextPageToken={this.props.nextPageToken}
/>
);
}
/* ... */
fetchMoreComments = () => {
if (this.props.nextPageToken) {
this.props.fetchCommentThread(this.getVideoId(), this.props.nextPageToken);
}
};
}
function mapStateToProps(state, props) {
return {
youtubeLibraryLoaded: getYoutubeLibraryLoaded(state),
channelId: getChannelId(state, props.location, 'v'),
nextPageToken: getCommentNextPageToken(state, props.location),
};
}
function mapDispatchToProps(dispatch) {
const fetchWatchDetails = watchActions.details.request;
const fetchCommentThread = commentActions.thread.request;
return bindActionCreators({fetchWatchDetails, fetchCommentThread}, dispatch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.