Last active
April 3, 2019 09:04
-
-
Save kawnayeen/7c5d04ff377d23a3c61f0a28af7a73e5 to your computer and use it in GitHub Desktop.
Enhanced Youtube #2 - Search from youtube
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
// 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