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
0 answers

useSWR doesn't get data

I have a useSWR call that calls a fetcher. The fetcher gets the data as shown in the log but useSWR doesn't error or get the data, it just stays in the loading state. I have other calls that use the same format without issue so I don't know what's…
0
votes
1 answer

useSWR not getting data from api while fetch() to the same adress returns data

I really don't understand why I can't get useSWR to work in my app. I have been trying for two days and can't seems to find the reason. The normal fetch works fine calling the same address in the same function. const address =server+…
Marcus Vr
  • 1
  • 2
0
votes
1 answer

How to update an item after being newly created in AWS DynamoDB and Amplify

I am trying to update a query in AWS Dynamo using AWS Amplify on top of Next.js. My scenario is simple. On page load, if there exists a user and the user has not visited a page before, a new object will be created with set values using SWR. const…
Tyler Morales
  • 1,440
  • 2
  • 19
  • 56
0
votes
1 answer

How to fix Error: Rendered more hooks than during the previous render when using SWR with useEffect

I a having an issues using SWR with useEffect hook. I am getting the error Rendered more hooks than during the previous render. My code is as follows: const { id } = router.query; const { data: recipe } = useRecipe(id); if (recipe) { …
adherb
  • 304
  • 3
  • 12
0
votes
2 answers

The UseSWR hook not working in nextjs component

I am trying to use the useSWR hook to fetch data from an API. The API and requests works fine but the data is never updating. Here is the code: import useSWR from 'swr' import { SERVER_URL } from '../config'; import axios from 'axios' const fetcher…
Guy Mayo
  • 23
  • 6
0
votes
1 answer

Use swr with Next global context: entire page gets re-rendered

I have the following piece of code: function MyApp({ Component, pageProps }: AppProps) { const { tronLinkAuth, tronLinkLoading, mutateTronLink } = useTronLink(); const { authenticatedUser, authLoading, authLoggedOut, mutateAuth } =…
html_programmer
  • 18,126
  • 18
  • 85
  • 158
0
votes
0 answers

SWR: How do you use the compare option in the SWR hook?

According to the documentation of SWR: React Hooks for Data Fetching, there is an options object which can be passed in for more control of the hook. The documentation mentions a compare option: compare(a, b): comparison function used to detect…
Antonio Pavicevac-Ortiz
  • 7,239
  • 17
  • 68
  • 141
0
votes
1 answer

SWR fetch data based on selected value in dropdown

is it possible in swr to fetch data based on the selected value in a dropdown? At first fetch it is working but when I select the previous selected value it won't fetch the correct data. Fetch API const { data: entities } = useSWR( …
rainz
  • 81
  • 1
  • 8
0
votes
0 answers

Should a swr hook not be used in the _app.js file because of performance issues?

I have a Layout component which I'd like to use as a wrapper for my pages. pages/_app.js import { UIProvider, uiState } from '../components/Context/UIContext' import { UserProvider, userState } from '../components/Context/UserContext'; import {…
Antonio Pavicevac-Ortiz
  • 7,239
  • 17
  • 68
  • 141
0
votes
0 answers

An alternative to `any` when doing type safe data fetching with SWR?

The React data fetching library SWR has an example using the library with typescript here. In the example, a fetcher function is defined that wraps fetch and which is then passed to the useSWR hook to do the actual data fetching. export default…
P4nd4b0b3r1n0
  • 1,951
  • 3
  • 22
  • 31
0
votes
1 answer

Can i use SWR Hook with pure React / Create React App?

SWR Hook created by Vercel and it was recommending for Data fetching of Next.js So can i use SWR Hook with pure React / Create React App ?
Anna
  • 228
  • 1
  • 3
  • 13
0
votes
2 answers

React custom hook causes infinite loops

any idea why this custom hook with SWR causes an infinite loop? export const useOrganization = () => { const [data, setData] = useState(); const { organizationId } = useParams(); const { data: dataSWR } =…
0
votes
2 answers

Why useSWRInfinite call my backend twice for every request?

I have a load more button, within a brand new Next.js app, that uses useSWRInfinite. Every time I click it it makes 2 calls to my backend. The first call is with index 0 and the second is with the incremented index. Here is my component: function…
grabury
  • 4,797
  • 14
  • 67
  • 125
0
votes
1 answer

Implement Load More button in Next JS

I am using SWR package with Next JS. I am able to get the data using these and able to display that data in the table. But now I want to show the load more type of pagination on the page of the listing. here below is my code: Locations…
Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75
0
votes
0 answers

How to pass headers when using SWR axios and nextjs

I am attempting to switch my api usage to use SWR as it provides much more customisation options that I could very well benefit from. How ever the api GET request need to pass through 2 headers 'Authorization':Bearer ${session.accessToken} and…
MatDoak
  • 132
  • 5
  • 17