1.0.1 • Published 12 months ago

use-recursive-fetch-paginate v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

use-recursive-fetch-paginate

Data from APIs are commonly paginated. We also have often use cases when we have to fetch all the records from an API. For example, when we want to make data visualizations. Therefore, we have to iteratively fetch all the pages which contain the data we need.

Usage

 const [results, fetchData] = useRecursiveFetchPaginate<
    ProductsResponse
  >(getAllProductsByParam, null, {
    debug: true,
    until({ total }) {
      return total >= 1000
    },
    callback(products) {
      console.log('callback data', products)
    },
    finally(products) {
      console.log('results', products)
    },
  })
  
 // Call
 useEffect(fetchData, [fetchData])

Requests

The structure of the call stack is evident when looking at the network requests after running the function.

Screen Shot 2023-02-02 at 22 17 36

Installation

Download the latest use-recursive-fetch-paginate from GitHub, or install with npm:

npm install use-recursive-fetch-paginate

License

This program is free software; it is distributed under an MIT License.

1.0.1

12 months ago

1.0.0

1 year ago