Swr: Add useSWRPages api to Readme.md

Created on 4 Nov 2019  路  11Comments  路  Source: vercel/swr

Add useSWRPages api to Readme.md

documentation pagination

Most helpful comment

The hook useSWRPages is going to be deprecated and replaced by useSWRInfinite https://github.com/vercel/swr/pull/435

All 11 comments

Will do after shipping #95

@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.

Just bumping this so it hopefully gets resolved :)

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.

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

@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.

SWR have many features but look like Vercel hide it. Low level dev like me need some docs to use power of SWR.

The hook useSWRPages is going to be deprecated and replaced by useSWRInfinite https://github.com/vercel/swr/pull/435

useSWRInfinite

seems like we just have to change the title of this issue to Add useSWRInfinite API to README because it was the https://github.com/vercel/swr/pull/435 was merged but it's not on the README yet?

Any updates on adding useSWRInfinite to the README? Seems like a very useful feature..

Hi all, we are gonna ship the docs for useSWRInfinite soon.

PR: https://github.com/vercel/swr-site/pull/24

Was this page helpful?
0 / 5 - 0 ratings

Related issues

needcaffeine picture needcaffeine  路  3Comments

Ephys picture Ephys  路  3Comments

nainardev picture nainardev  路  4Comments

bbenezech picture bbenezech  路  5Comments

bywo picture bywo  路  4Comments