#Custom data fetching hook

4 messages · Page 1 of 1 (latest)

storm pike
#

Hey guys,

It would be really helpful if someone can provide some examples as to how to configure a custom data fetching hook using swr,

such that it returns repeat queries from cache directly,

More context:
https://twitter.com/JeroenReumkens/status/1619183996575035392?s=20

@zomars @trpcio My approach is to repeat the query if you need to pass data down more than one level from where it was first queried. The react query cache should be configured in such a way that repeat queries aren’t ran but return directly from cache. So little overhead but way better DX.

frank sentinel
#

isn't this already the default behavior?

storm pike
#

Yes I think swr by default stores in cache but wanted to know if there are any other configs which I am missing on

frank sentinel
#

the default config is what was considered the best for most apps, you can tweak them if your app has a specific requirement. all configs are documented: https://swr.vercel.app/docs/api#options

SWR is a React Hooks library for data fetching. SWR first returns the data from cache (stale), then sends the fetch request (revalidate), and finally comes with the up-to-date data again.