aribouius / jsonapi-react

A minimal JSON:API client and React hooks for fetching, updating, and caching remote data.
MIT License
149 stars 28 forks source link

Provide example of pagination implementation. #65

Closed hoIIer closed 1 year ago

hoIIer commented 1 year ago

I was just curious if there are any public examples or ones that could be shared of pagination with this library?

For instance with useQuery() I've so far placed it at top of my component, but generally with pagination I would place the api call into a fetchData(params={}) type function that gets called on initial render, and then subsequently as user scrolls to the bottom of the list.

I saw that <FlatList> has onEndReached={} which allows calling e.g. fetchData() again, which we'd want to then pass in the pagination links from the first call, but unsure how to package this in react form (newish to react).

Initially I was passing data from const { data } = useQuery('foos') straight into <FlatList data={data}/>, but thinking we'd want to instead check for data existing, then add those objects to a component-level items[] array which gets passed into <FlatList>, and subsequently new items added on each new paginated query?

Any help appreciated!