this is my code:
JavaScript
x
57
57
1
import "./styles.css";
2
import "mvp.css";
3
import { useState, useEffect } from "react";
4
import axios from "axios";
5
6
function Books() {
7
const [book, setBook] = useState("");
8
const [result, setResult] = useState([]);
9
const [apiKey, setApiKey] = useState(
10
""
11
);
12
function handleChange(event) {
13
const book = event.target.value;
14
15
setBook(book);
16
}
17
18
function handleSubmit(event) {
19
event.preventDefault();
20
21
axios
22
.get(
23
"https://www.googleapis.com/books/v1/volumes?q=" +
24
book +
25
"&key=" +
26
apiKey +
27
"&maxResults=100"
28
)
29
.then((data) => {
30
console.log(data);
31
});
32
}
33
34
return (
35
<div className="App">
36
<h1>Search For A Book</h1>
37
<form onSubmit={handleSubmit}>
38
<div className="form-group">
39
<input
40
type="text"
41
onChange={handleChange}
42
className="input"
43
placeholder="Search..."
44
/>
45
<button type="submit" className="btn">
46
Go!
47
</button>
48
</div>
49
</form>
50
</div>
51
);
52
}
53
54
export default function App() {
55
return <Books />;
56
}
57
Is anyone able to figure out why I am unable to get this to work? I keep getting a Request failed error and I am not sure what is going wrong. I have manually entered my url into the my browser such as this:
https://www.googleapis.com/books/v1/volumes?q=javascript&key=APIKEY
But when I do it through my code it is not working.
Thanks in advance.
Advertisement
Answer
maxResults should be less than <= 40 according to recommendation. Update the max result in code. It would work after that