DEV Community

Cover image for What made me use SWR?

What made me use SWR?

Aastha Pandey
I write only on those topics, wherein I myself was stuck at some point in time.
・1 min read

I have been working on a project which have multiple screens and since I am using react I have to deal with several components but when it came to data fetching it wasn't easy to use the hook called useEffect, I was able to control the useEffect functionalities to some extent using dependency array but the component was mounting and unmounting which made it to refetch the data every single time.
When I learnt about SWR it kind of gave so many functionalities that I could use to control the number of refetches so the first thing I used was, dedupingInterval here I can set the time interval when I need to refetch the data.
Second thing which I used was,
mutate(key): what are the other scenarios I would like to refetch or I can say invalidate the old call.

Discussion (1)

carrotfarmer profile image
Dhruva Srinivas • Edited

Nice article! Even I was a bit skeptical about using useEffect for my new project

Forem Open with the Forem app