use-recursive-fetch-paginate
v1.0.1
Published
React hook for handling fetch data recursively from paginated api
Downloads
3
Maintainers
Keywords
Readme
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.
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.