Loader hits all API when loderDeps are updated.
I have two APIs for my route, one gets the table data and the other one gets filter data. Every time I change the page number in the loaderDeps I only want the table data API to hit since my filter data API is a huge list which is slowing down my app. And I need it only once, so it doesn't make sense to hit it every time
2 Replies
xenial-black•2y ago
This sound like a time to add some caching behaviour into your application.
The basic concept of a loader is that it runs every time. Opting out of it for certain requests would require some sort of cachinng solution. I tend to use TanStack Query and use a
staleTime that works for me, so I don't fetch redundant data.
Because to opt out of requests for certain loader runs, means that you need to be able to track that a request has been made, and then conditionally allow for a refetch of data for certain calls.
Ofc, this is something you could implement yourself, but when there purpose built libs for this, it may be worth taking a look at those.