After using it for a long time, I have a few questions, and welcome to discuss #554
-
swr is an amazing lib. I like many of its features, such as Local mutation and Suspense mode. But I had several problems for using it
Among so many repeated requests, it is difficult to find the request I want, Is it because my code is wrong?
I have used swr for a long time, but I still haven't found the best practice. and you? ? ? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
I think we could using swr handling all of the get requests. The reason there are many repeating requests is that swr will do the data validation on some specific times, such as component oMount, page onFocus, etc. you can turn off the validation in the
For best practice, I want to share my experience:
But I still figuring out is that worth to do this? 🤔 |
Beta Was this translation helpful? Give feedback.
-
@Kexin-Li the response data for |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Thank you everyone. My English is very poor, so some words misunderstood you, and i will not send post/delete request buy swr .Especially thank you @sergiodxa |
Beta Was this translation helpful? Give feedback.
I tend to use SWR for everything, but if you know you will never want to update some value, it could make sense to fetch it once, store it in a state and share it through context.
That is common, it's because SWR is revalidating on focus, and if you open your devtool your focus will move between the devtools and your app, so everytime you focus again in the app it will trigger more request, you can disable it with
revalidateOnFocus: false
.I think the best way to solve this is to cache the data.
I don't see a reason to do not do it, actually it makes a lot of sense to use SWR to fetch data for a graph, this way your graph will keep up-to-date, what you may want to do is to useMemo…