Skip to content

[feature request] Allow pagination by cursor instead of page/offset #188

@soteri-scottmmjackson

Description

@soteri-scottmmjackson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions