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

React Next app not working as expected, most likely hook updating issue

I've been banging my head against my desk for the past hour trying to figure out why the following code only displays the loading spinner and never updates to show the actual data even when I can see the data logged in the console, so I know the…
thowitz
  • 38
  • 3
0
votes
1 answer

Next.js - SWR hook question about dedupeInterval and refreshInterval

I'm using SWR hook along with next.js for the first time and i've tried to get some answers about something but i couln't get them, not even with the docs. Questions: So, i know SWR provides a cache with your data, and it updates in real time, but…
Diego
  • 421
  • 3
  • 9
  • 34
0
votes
1 answer

SWR hook with next.js - typescript / issue

I've posted some questions about SWR hook here, because in my journey trying to use it has been a little bit hard since i'm having some problems with it Now this time the error seems small. What i'm trying to do is to git a breakpoint in my API…
Diego
  • 421
  • 3
  • 9
  • 34
0
votes
1 answer

useSWR integration with pagination on backend

When page changes, new query is created and it's data is set to initialData. In this case user sees initialData before new query data is fetched: import React from "react"; import fetch from "../lib/fetch"; import useSWR from "swr"; function…
Ioan Ungurean
  • 319
  • 1
  • 15
0
votes
1 answer

Logout user and remove all requests called by useSWR

I have auth with axios and interceptors and I am having issue with the user logout. When a accessToken is invalidated I am calling revalidate with a refreshToken. When is even the refreshToken invalid I want to logout a user, but I am not sure how…
Dawe
  • 562
  • 1
  • 9
  • 19
0
votes
1 answer

useSWR hook behaving erratically or possible stale closure

I have a React functional component that renders a Lesson Video Player in a very similar way to the Instagram Stories. Some of those videos ("clips") in a lesson have "interactions" that pop up a card where the user answers a multiple-choice quiz.…
Marcos
  • 1,043
  • 10
  • 15
0
votes
0 answers

How to use SWR mutate function with multiple keys but same type object array

I'm stuck with Vercel's SWR mutate system. I'm going to try to explain my situation, I hope I can make it. I'm working on a social media app, it's something like a combination of Instagram and Twitter. We have a weird RestAPI design in here. for…
mafirat
  • 258
  • 1
  • 8
0
votes
1 answer

useSWR - How to pass config object to fetch

I'm trying to integrate useSWR in a next js project I'm working on. I want to pass a config to fetcher as an argument. I have read about Multiple Arguments in the docs but it's not returning the data for some reason. it is making the api request I…
Xaarth
  • 1,021
  • 3
  • 12
  • 34
0
votes
2 answers

Is it possible to send the pages id in nextJS ussing useSWR so I can fetch data based on the ID of the page I am on

I am doing a request with useSWR in next js and the api route needs the id of the page I am on, it is in the query params at router.query.id But how do i pass that to useSWR so I can pull in the right data from my api router function that talks to…
Anders Kitson
  • 1,413
  • 6
  • 38
  • 98
0
votes
1 answer

How can i use the useSWR hook when my response need to do some logical operations before next dependant API call

I'm using swr in a CRA app and need to use the useSWR hook for data fetching that is both dependant and conditional. What i need to do is: Call an api to get an id which i will use for a second api call. the id is located in either upcomingEvents…
dny
  • 1
  • 3
0
votes
1 answer

Ternary operator doesn't work as expected

I have a map component where I need to pass default coordinates which will be coming from custom useSwr hook. After fetching the data I pass them to the state and render it if the values or not undefined. Apparently I do something wrong and its not…
em_code
  • 379
  • 5
  • 17
0
votes
1 answer

Why is my cached state undefined on mutate in SWR?

I have a component that gets the data for a subreddit with posts and every post has a vote: const subUrl = `/api/subreddit/findSubreddit?name=${sub}`; const { data: fullSub, error } = useSWR(subUrl, fetchData, { initialData: props.fullSub,…
GeraltDieSocke
  • 1,524
  • 3
  • 20
  • 51
0
votes
0 answers

How is it that useSWR issues an object when it needs an array?

I have useSWR and I put data with SSR into it as an initial and get an array. If I make a console log of chats from SSR, then they regularly display normal information. The problem is that useSWR sometimes miraculously returns an OBJECT to me or…
0
votes
1 answer

Error: Invalid hook call. when calling hook after await - how do you await for data from one hook to instantiate into another?

Im trying to inject a header into my fetcher before using swr to fetch the data. I need to await for a custom hook to respond with the data before I can inject it into the custom fetcher. If I use a promise.then I know i'm getting the relevant data,…
user9196065
0
votes
0 answers

Fetching data with input parameter with SWR Hook

function DayOne() { const [country, setCountry] = useState(""); const url = `${process.env.REACT_APP_BASE_URL}/dayone/all/total/country/${country}`; const { data, error } = useSWR(url, fetcher); let value = useRef(""); const onClick =…
Fernando Correia
  • 111
  • 1
  • 2
  • 11
1 2 3
24
25