https://github.com/natserract/use-recursive-fetch-paginate
React hook for handling fetch data recursively from paginated api
https://github.com/natserract/use-recursive-fetch-paginate
Last synced: 2 months ago
JSON representation
React hook for handling fetch data recursively from paginated api
- Host: GitHub
- URL: https://github.com/natserract/use-recursive-fetch-paginate
- Owner: natserract
- License: mit
- Created: 2023-02-02T13:46:08.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-01T02:36:19.000Z (over 2 years ago)
- Last Synced: 2025-07-14T06:16:35.374Z (3 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/use-recursive-fetch-paginate
- Size: 166 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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
```tsx
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](https://github.com/natserract/use-recursive-fetch-paginate) from GitHub, or install with npm:
```sh
npm install use-recursive-fetch-paginate
```## License
This program is free software; it is distributed under an [MIT License](https://github.com/natserract/use-recursive-fetch-paginate/blob/main/LICENSE).