Questions tagged [swr]

SWR is a React Hooks library for remote data fetching.

The name “SWR” is derived from stale-while-revalidate, a cache invalidation strategy popularized by HTTP RFC 5861. SWR first returns the data from cache (stale), then sends the fetch request (revalidate), and finally comes with the up-to-date data again.

369 questions
0
votes
1 answer

Multiple SWR calls not returning data in React component

I am using React functional component where I need to make 2 calls to different APIs. My code below hits both the fetcher functions and the result is printed inside. However, the value is not received when in return block. What is wrong here? The…
Chilarai
  • 1,842
  • 2
  • 15
  • 33
0
votes
0 answers

User is logged in and X-XSRF-TOKEN is passed in the headers but just displaying 401 Unauthorized in Laravel Sanctum & NextJs

I am developing a NextJs app with a Laravel backend. I chose to go with Token based authentication. Logging in and fetching user data via Postman is working fine. But it's only returning 401 Unauthorized on the NextJs app for fetching user data even…
Frank
  • 321
  • 1
  • 3
  • 11
0
votes
1 answer

data undefined with useSWR

I'm trying to use useSWR in my NEXT.JS app. First, I made a custom hook where I use it : import useSWR from "swr"; const apiUrl = process.env.NEXT_PUBLIC_API_URL; const fetcher = (url) => { fetch(url).then((res) => res.json()); }; export…
0
votes
1 answer

SWR optimistic mutation

I am building a small app to sign up users to sing a karaoke music. I am using SWR to fetch info from a mongoDB and due to performance issues I am trying to implement optimist UI. Although, I can't seem to make it work... When a song is…
0
votes
0 answers

API fetch with swr returns 'undefined'

I created a Next.JS API which extracts data from a CSV file and returns the data, which works fine. res.status(200).json(upCommingDates); which returns the following when accessing it: ["2022-12-11T23:00:00.000Z","2023-11-26T23:00:00.000Z"] The…
pawl133
  • 3
  • 2
0
votes
0 answers

SWR: How to efficiently handle filtering?

Let's say that we are displaying books grouped by author. The GET request would look as follows: // The server parses this like: author=['tolkien', 'shakespeare'] const data = useSWR('example.com/books?author[]=tolkien&author[]=shakespeare') After…
Marnix.hoh
  • 1,556
  • 1
  • 15
  • 26
0
votes
0 answers

Use SWR to fetch data from Supabase

I'm stuck trying to fetch comments for a specific post, currently fetching returns all the comments on the site. Olny need posts for the specific post id. [slug].js I'm using const { data: commentList, error } = useSWR(`/api/comments/`, …
PDANGER
  • 87
  • 11
0
votes
0 answers

how to use SwrInfinite when working with pagination

I am using pagination of swrInfinite. Using url `https://api.rarible.org/v0.1/items/byCollection?collection=${id}&size=${results}&continuation=${cont}` full results handling page link. I just want to send request again with change the results value…
Anish Ali
  • 31
  • 3
0
votes
0 answers

useSWRInfinite with refresh interval and revalidateFirstPage flag on false

I recently discovered SWR and I'm trying to use it for a web page that needs real time updates. I also have a load more button so I use useSWRInfinite. My problem is that every time I load a new page the first gets revalidated, which makes the…
Maria Noaptes
  • 104
  • 1
  • 8
0
votes
0 answers

how to edit data in useSWR

export function Home() { const { data } = useSWR("/comments"); const { data: editData, mutate } = useSWR("/comments", { revalidateOnFocus: false, }); const onEdit = async () => { await axios.post("/comments",…
JeongHaSeung
  • 393
  • 6
  • 12
0
votes
1 answer

How to use swr hook with suspense enable in pages folder Nextjs?

I am trying to use SWR hook in my project but I have an issue when I enable option suspense to true, I have put SWR hook inside home page component but it not works with suspense option, so I had to put it inside child component for suspense to…
Epple
  • 640
  • 14
0
votes
1 answer

Unable to display JSON record retrieved from SWR in NextJs

I am receiving an error when trying to display a JSON record retrieved using SWR, but the record appears correctly when displayed to the console using console.log. TypeError: Cannot read properties of undefined (reading 'name') import useSWR from…
HamletHub
  • 481
  • 1
  • 9
  • 19
0
votes
1 answer

Accessing response error data in next.js using SWR

I have a form data which on submit I a sending to backend if there is an error I have process the error and show it on page. Request is getting posted fine but when getting a backend response I never go to catch error loop. Appreciate any help in…
divein
  • 57
  • 1
  • 11
0
votes
1 answer

NextJS API Endpoints returning Internal Server Error when deployed on IIS

In local development, everything works as expected. Frontend calls the Nextjs API endpoints and receives the response with data. However, when deployed to a IISNode, running on a Windows Server 2012 R2, API calls return only a Status Code 500…
gabril
  • 28
  • 5
0
votes
1 answer

SWR returns empty string

So here's my situation: I upload a file and send it to an API then i get back a response with an object with some data in it. This is how i send it to the API: apiRoute.post(async (req, res) => { try { const media_url =…
Ilir
  • 488
  • 5
  • 20