-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (38 loc) · 1.24 KB
/
index.js
File metadata and controls
49 lines (38 loc) · 1.24 KB
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
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import SearchBar from './components/search_bar';
import YTSearch from 'youtube-api-search';
import VideoList from './components/video_list';
const API_KEY = 'AIzaSyDVG9z8VPdHsQbpE8WI4uh0iR1WqTU3i7s'
//create a new component that produces
//some html
// const App = () => {
// return (
// <div>
// <SearchBar/>
// </div>
// );
// }
//making app a class based component because need to use state
class App extends Component {
constructor(props){
super(props);
this.state = { videos: [] };
YTSearch({key: API_KEY, term:'surfboards'}, (videos) => { //value named as video to be passed to below
this.setState({videos});
console.log(videos);
//this.setState({videos: videos}); //this is the short form of above because the key and value pair is of same name
});
}
render(){
return (
<div>
<SearchBar/>
<VideoList videos = {this.state.videos}/>
</div>
);
}
}
//take this component generated HTML
//and put on the page
ReactDOM.render(<App />, document.querySelector('.container'));