The Wayback Machine - https://web.archive.org/web/20200525201635/https://github.com/zeit/swr/issues/70
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

Add useSWRPages api to Readme.md #70

Open
Go7hic opened this issue Nov 4, 2019 · 6 comments
Open

Add useSWRPages api to Readme.md #70

Go7hic opened this issue Nov 4, 2019 · 6 comments
Labels

Comments

@Go7hic
Copy link
Contributor

@Go7hic Go7hic commented Nov 4, 2019

Add useSWRPages api to Readme.md

@shuding
Copy link
Member

@shuding shuding commented Nov 8, 2019

Will do after shipping #95

@shuding shuding mentioned this issue Nov 9, 2019
2 of 3 tasks complete
@derekblank
Copy link

@derekblank derekblank commented Nov 14, 2019

@quietshu I'm having a bit of trouble understanding what the page key is meant for, and what is happening in the following section. Perhaps you could describe that a bit more in the README or examples?

    // get next page's offset from the index of current page
    (SWR, index) => {
      // there's no next page
      if (SWR.data && SWR.data.length === 0) return null

      // offset = pageCount × pageSize
      return (index + 1) * 3
    },

    // deps of the page component
    []

Also, how might one use mutate or trigger a manual revalidation while preserving the offset? In my use case I have a dashboard of items, with 20 items per page: item.json?page=1, item.json?page=2, etc., and would like to revalidate the data when a user adds an item, but I can't quite figure out how to trigger this and still preserve the offset.

@danpantry
Copy link

@danpantry danpantry commented Jan 3, 2020

Just bumping this so it hopefully gets resolved :)

@fnky
Copy link

@fnky fnky commented Jan 27, 2020

Also, how might one use mutate or trigger a manual revalidation while preserving the offset?

I'm running into the same issue. I have a list of items which can be selected. When selected, the item will show with details next to the list side-by-side. The details can be edited and should also reflect these changes in the list.

There doesn't seem to be a simple way to revalidate without having to somehow making the revalidate method accessible.

Another idea I had was to store each key that is requested in a global store and manually trigger each of them. Maybe even group the items with their offset to only trigger and revalidate that specific cache. But this is very convoluted.

@dhmacs
Copy link

@dhmacs dhmacs commented Apr 10, 2020

@shuding Looks like #95 has been shipped, is there a timeline for the docs?

@hems
Copy link

@hems hems commented Apr 30, 2020

@shuding Looks like #95 has been shipped, is there a timeline for the docs?

there is already some docs on the file itself, you can see it here:
https://github.com/zeit/swr/blob/master/src/use-swr-pages.tsx

And there is a nice tutorial about it here:
https://sergiodxa.com/articles/swr/pagination/

Would be nice if someone copied some of those and added as example on the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
7 participants
You can’t perform that action at this time.