-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
63 lines (44 loc) · 1.52 KB
/
Copy pathApp.js
File metadata and controls
63 lines (44 loc) · 1.52 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React, {Component} from 'react';
import BookInfo from './BookInfo';
class App extends Component {
constructor(props) {
super(props);
this.state = {
inputValue: '',
books: [],
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange (e) {
this.setState({inputValue: e.target.value});
}
handleSubmit (e) {
e.preventDefault();
const url = `https://www.googleapis.com/books/v1/volumes?q=:${this.state.inputValue}`
fetch(url)
.then(response =>
response.json())
.then((data) => {
console.log('bookInfo:', data.items)
this.setState({
books:data.items,
})
})
}
render() {
console.log('state:', this.state)
return (
<div className = 'App'>
<h1> Book Finder</h1><br/>
<form onSubmit={this.handleSubmit}>
<input type="text" placeholder= "Type author, book name, subject ..." inputvalue= {this.state.inputValue} onChange={this.handleChange}/>
<button type="button" onClick={this.handleSubmit}>Search</button>
</form>
< BookInfo
books={ this.state.books }/>
</div>
);
}
}
export default App;