Skip to content

Instantly share code, notes, and snippets.

@kawnayeen
Last active April 3, 2019 09:04
Show Gist options
  • Save kawnayeen/7c5d04ff377d23a3c61f0a28af7a73e5 to your computer and use it in GitHub Desktop.
Save kawnayeen/7c5d04ff377d23a3c61f0a28af7a73e5 to your computer and use it in GitHub Desktop.
Enhanced Youtube #2 - Search from youtube
// defining state
state = {
videos: [],
selectedVideo: null
};
// fetch video at startup
componentDidMount() {
this.searchNewVideos('Caspian Report')
}
// searching videos from youtube
searchNewVideos(searchTerm) {
console.log(searchTerm);
YTSearch({key: API_KEY, term: searchTerm}, videos => {
console.log(videos);
this.setState({videos});
if(this.state.selectedVideo===null){
this.setState({
selectedVideo: videos[0]
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment