Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the pagination API #95

Merged
merged 1 commit into from
Nov 8, 2019
Merged

Improve the pagination API #95

merged 1 commit into from
Nov 8, 2019

Conversation

shuding
Copy link
Member

@shuding shuding commented Nov 7, 2019

After this change, the SWR -> offset function will pass the entire SWR object (so you can get the error / loading state as well), as well as the index of current page. (pageSWRs could be overkill and useless, and it causes some data inconsistency issues.)

Before

swrDataToOffset(data, pageSWRs)

e.g.:

useSWRPages(
  ...,
  ...,
  (data, swrs) => offsetOfNextPage
)

After

SWRToOffset(SWR, index)

e.g.:

useSWRPages(
  ...,
  ...,
  ({ data, error, ... }, indexOfCurrentPage) => offsetOfNextPage
)

Also added an example for it.

@shuding shuding merged commit 82582e1 into master Nov 8, 2019
@shuding shuding deleted the improve-swr-pages branch November 8, 2019 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants