question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to reset pages of `useSWRPages`?

See original GitHub issue

Hi

I’m using swr for pagination in my local next.js project. My implementation is based on this example. The difference is that my component with useSWRPages is using dynamic route, which loads user’s feed, and the route looks like this: /user/[username].

The problem appears when I switch user feed with loaded pages. In more details:

  1. I, as a user, open user-A’s feed, then load a number of pages (let’s say 4).
  2. I change feed to user-B’s.
  3. User-B’s feed loads 4 pages, instead of 1.

I’d tried to pass username in to useSWRPages’s deps, and use it in key, but it didn’t helped me. Is there any workarounds? Maybe I should pass something else in to the deps?

There’s is an issue that seems like similar to mine: #126.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:17
  • Comments:28 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
telmencommented, Apr 13, 2020

Any progress on this?

5reactions
shudingcommented, Dec 13, 2019

Currently you can try

mutate('_swr_page_count_' + pageKey, 0)
mutate('_swr_page_offset_' + pageKey, 0)

as a temporary work around.

I will work on simplifying the useSWRPages API next week since it’s tricky to get it right (conditional and dependent hooks) and we have several bugs/feature requests around it. 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination - SWR
SWR is a React Hooks library for data fetching. SWR first returns the data from cache (stale), then sends the fetch request (revalidate),...
Read more >
Using Paginated Data with SWR by sergiodxa - Sergio Xalambrí
Along with useSWR , the SWR library gives us a useSWRPages hook which lets us do paginated data. The way it works is...
Read more >
An Introduction To SWR: React Hooks ... - Smashing Magazine
In this article, we'll be looking at a new way of retrieving data in React Apps named SWR. This is a set of...
Read more >
issues within React and rendering a compnent - Stack Overflow
Recently I'm trying to use this library: https://github.com/zeit/swr/blob/master/examples/pagination/pages/page-index.js but I just added one ...
Read more >
How To Reset Explore Page On Instagram - YouTube
Let's reset the Instagram explore page if you don't like what the Instagram app shows you on the search or for you page....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found