Is SWR the correct library for me? #763
Unanswered
JonCognioDigital
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
Simple question here but I'm not sure I understand if SWR does what I need it to do.
I'm after a simple data fetching library for use in a create-react-app (not next.js) for grabbing data on page transition. I was going to use "async react" which looks like a great library but SWR seems to have many more downloads and has been updated recently and often.
However, after installing it I noticed that after fetching the initial data it keeps making repeat calls to get fresh data - when you switch tabs and sometimes for no particular reason. Also, if it fails to get data it keeps trying. Now, I can see that it's possible to switch all of these behaviours off individually but am I going against the grain here? Is SWR designed for a use case I don't understand?
I do have some scenarios when I do need a call to be retried, e.g. when the user's security token changes. Each time I make a call to my API I need to intercept the call and check if the token is still in date, if it isn't then I need to cancel the call and ask the user to log in again. Once they have and the new token is put into redux I need all cancelled calls to retry, but just once.
I also need to post/patch data to the back end as often as I need to fetch data. This is a CRUD app.
Is what I'm trying to do possible or is SWR a tool for a different job?
Many thanks.
Beta Was this translation helpful? Give feedback.
All reactions