`Constantly comes a different answer from the answer from google book. How to solve the loading problem?
7
7
700Hp2021-10-23 19:05:14
React
700Hp, 2021-10-23 19:05:14

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
}


axios root
import axios from 'axios'

const $host = axios.create({
    baseURL: process.env.REACT_APP_API_URL
})

export {
    $host
}


process.env.REACT_APP_API_URL == localhost:3000

Mobx
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
    }
}


Book request:
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)
        })
    }


On the button to see more, we load the rest:
const test = async () => {
        setLoader(true)

        await getMoreBooks(value, startIndex).then(data => {
            books.setMoreBooks(data.items)
            setCards(books._books)
            setStartIndex(startIndex + 29)

        })
        setLoader(false)
    }


The problem is the following. The primary query shows 183 items found. Loads 30.
By clicking to see more, loads the second 30 and so on 3 times. The problem is that for 3 times, in the console, it shows that now not 183 elements were found for the same query, but 170. And so on.

There is a mistake in my request and it is worth releasing pagination differently. Or a google api problem?

617432e00efa1417876415.png617432e61f55d832129090.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question