OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

useSWR in Astro only refetches when refocussing page

  • Thread starter Thread starter Daniell
  • Start date Start date
D

Daniell

Guest
I want to make sure I always get the latest data from an API endpoint, but currently I only get the latest data when I refocus my page

The endpoint I'm requesting contains the following header: "Cache-Control": "public, s-maxage=60, stale-while-revalidate=30"

Inside my React component I have:

Code:
export function SpotifyTrackList() {
  const { data } = useSWR<APIResponse>("/api/spotify", fetcher);

Which I import in my Astro component:

Code:
<SpotifyTrackList client:only="react" />

I only see a refetch happening when I refocus my page however. I would expect it to respect the header's timeout so a refetch would happen without me necessarily having to refocus the page

<p>I want to make sure I always get the latest data from an API endpoint, but currently I only get the latest data when I refocus my page</p>
<p>The endpoint I'm requesting contains the following header: <code>"Cache-Control": "public, s-maxage=60, stale-while-revalidate=30"</code></p>
<p>Inside my React component I have:</p>
<pre><code>export function SpotifyTrackList() {
const { data } = useSWR<APIResponse>("/api/spotify", fetcher);
</code></pre>
<p>Which I import in my Astro component:</p>
<pre><code><SpotifyTrackList client:only="react" />
</code></pre>
<p>I only see a refetch happening when I refocus my page however. I would expect it to respect the header's timeout so a refetch would happen without me necessarily having to refocus the page</p>
 

Latest posts

Top