Last active
November 18, 2018 14:05
-
-
Save productioncoder/70f50bdf78692b714e9235119b91a63c to your computer and use it in GitHub Desktop.
Youtube in React: infinite scroll for trending videos
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 {InfiniteScroll} from '../../components/InfiniteScroll/InfiniteScroll'; | |
/* ... */ | |
class Trending extends React.Component { | |
render() { | |
const previews = this.getVideoPreviews(); | |
const loaderActive = this.shouldShowLoader(); | |
return ( | |
<React.Fragment> | |
<SideBar/> | |
<div className='trending'> | |
<InfiniteScroll bottomReachedCallback={this.fetchMoreVideos} showLoader={loaderActive}> | |
{previews} | |
</InfiniteScroll> | |
</div> | |
</React.Fragment> | |
); | |
} | |
shouldShowLoader() { | |
return !this.props.allMostPopularVideosLoaded; | |
} | |
/* ... */ | |
fetchMoreVideos = () => { | |
const {nextPageToken} = this.props; | |
if (this.props.youtubeLibraryLoaded && nextPageToken) { | |
this.props.fetchMostPopularVideos(12, true, nextPageToken); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment