Modern pagination many times is done via a cursor string rather than a page/offset. This is particularly useful when the result set size is unknown or may be resource-intensive to calculate, and is not of particular use to the end user in any event.
My current workaround is as follows:
const WrappingComponent = () => {
const [queryParams, setQueryParams] = useState({});
const mapResponse = useCallback((response) => {
setQueryParams({ cursor: response.next })
return {
options: response.options,
hasMore: !isNil(response.next),
};
}, [])
const get = useCallback((url, {search, cursor}) => searchFunction(url, search, cursor), []);
return <WrappedSelectFetch
url="url"
// hack to carry cursor to next request
queryParams={queryParams}
get={get}
mapResponse={mapResponse}
// ...
/>
}
This is necessary because:
- useMapToAsyncPaginate improperly blows away any
additional set in the response mapper to overload with its own page incrementer
- There is no other way to move data from the response mapper as held state to the next request save for moving the state in a wrapping component.
What would be cool instead would be if:
a. We didn't blow away additional from mapResponse, OR
b. We specifically had a path for cursor-paged endpoints.
I think the first one leaves a bigger emergency hatch.
Modern pagination many times is done via a cursor string rather than a page/offset. This is particularly useful when the result set size is unknown or may be resource-intensive to calculate, and is not of particular use to the end user in any event.
My current workaround is as follows:
This is necessary because:
additionalset in the response mapper to overload with its own page incrementerWhat would be cool instead would be if:
a. We didn't blow away
additionalfrommapResponse, ORb. We specifically had a path for cursor-paged endpoints.
I think the first one leaves a bigger emergency hatch.