-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (39 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import _ from 'lodash';
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import YTsearch from 'youtube-api-search';
import SearchBar from './components/searchBar';
import VideoList from './components/videoList';
import VideoDetail from './components/videoDetail';
const API_KEY = 'AIzaSyCeaiuIb0sxF-wdniCDshqY0mL4_2cJQGk';
class App extends Component{
constructor(props){
super(props);
this.state = {
videos: [],
selectedVideo: null,
};
this.videoSearch('react native');
}
videoSearch(term){
YTsearch({key: API_KEY, term: term },(videos)=> {
this.setState({
videos:videos,
selectedVideo : videos[0]
});
})
};
render() {
const videoSearch = _.debounce((term) => {this.videoSearch(term)},300);
return(
<div>
<SearchBar onSearchTermChange={videoSearch} />
<VideoDetail video={this.state.selectedVideo} />
<VideoList
onVideoSelect={selectedVideo => this.setState({selectedVideo})}
videos = {this.state.videos}/>
</div>
)
};
}
ReactDOM.render(<App />,document.querySelector('#root'));