Answer the question
In order to leave comments, you need to log in
`
Constantly comes a different answer from the answer from google book. How to solve the loading problem?
Request:
import {$host} from './index'
export const getBooks = async (input) => {
const response = await $host.get(`volumes?q=${input}&maxResults=30`)
return response.data
}
export const getMoreBooks = async (input, start) => {
const response = await $host.get(`volumes?q=${input}&startIndex=${start}&maxResults=30`)
return response.data
}
import axios from 'axios'
const $host = axios.create({
baseURL: process.env.REACT_APP_API_URL
})
export {
$host
}
import {makeAutoObservable} from "mobx"
export default class BookStore {
constructor() {
this._books = []
makeAutoObservable(this)
}
setIsBooks(books) {
this._books = books
}
setMoreBooks(books) {
this._books = this._books.concat(books)
}
get isBooks() {
return this._books
}
}
const handleSubmit = async () => {
setLoader(true)
await getBooks(value).then(data => {
if (data.totalItems > 0) {
books.setIsBooks(data.items)
setAllItems(data.totalItems)
setCards(books._books)
setStartIndex(29)
} else {
console.log('Ничего не найдено')
setAllItems('Ничего не найдено')
}
setLoader(false)
})
}
const test = async () => {
setLoader(true)
await getMoreBooks(value, startIndex).then(data => {
books.setMoreBooks(data.items)
setCards(books._books)
setStartIndex(startIndex + 29)
})
setLoader(false)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question