vercel / swr-site

The official website for SWR.
https://swr.vercel.app
Apache License 2.0
481 stars 351 forks source link

Feedback for “Usage with Next.js” #558

Open AnilAragala opened 8 months ago

AnilAragala commented 8 months ago

Hi Team, I am using SWR to cache the api data to use entire session until page get reload or refresh. I want to hit the api only once when the user visits the page first time and don't want to hit again when user revisit the page.

Here is the scenario:

  1. User will login to the home page and visits the blog page. blog page has the api functionality to catch the data and use the entire session until page get refresh.
  2. And the user go back to home page and revisit the blog page i need to use cached data without hitting a api call.

Is there any solution for this scenario. I tried all the options like revalidateOnMount, revalidateOnFocus and mutate and etc. But, no luck.

Your help is highly appreciated.

Thank you

koba04 commented 8 months ago

@AnilAragala Doesn't useSWRImmutable fit in your case? https://swr.vercel.app/docs/revalidation.en-US#disable-automatic-revalidations

If so, could you create a CodeSandbox project to reproduce it?