Deduplicate requests #608
-
swr deduplicates requests. See dedupingInterval under options. Does react-query do this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
React Query does this automatically by tracking and sharing promises via the query key. So if 3 requests to fetch the same query are made close to each other, the first will actually fire, create a promise, and the next two will use the promise created by the first. One request, one promise, three promise resolutions. |
Beta Was this translation helpful? Give feedback.
-
If you’re referring to a delay *after* the request finishes, no that’s not a feature. In our findings, we couldn’t identify a use case for it since it can easily result in expecting to see fresh data but getting outdated data instead. Together with staleTime and the optional refetchOnMount options, you can achieve more reliable results.
That said, I could be swayed to add a delay option if a decent use case is presented.
…On Jun 23, 2020, 7:46 PM -0600, Cory House ***@***.***>, wrote:
Gotcha. So there's no way to specify a window for deduping, correct? Thanks for the quick reply!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
continuing this discussion, does the deduping feature not work when the refetch is run? |
Beta Was this translation helpful? Give feedback.
-
Hi @tannerlinsley @TkDodo I have a question on this relating to refetches. Our use case is within React Native with React Navigation, and we want to refetch certain queries when a screen returns to focus after being overlaid by a modal containing a web/non-native journey. Inside that web journey the user could modify something about their data, and therefore we want to ensure that when they're finished inside that modal journey and they return to the screen, that we're displaying the latest data in the app. We're using an The de-duplication topic came up in regard to preventing a user potentially spamming the server with refetch requests by repeatedly causing the screen to come in and out of focus - but not quickly enough to be caught by the promise-based deduplication that you describe. Since Any thoughts would be greatly appreciated 🙏 |
Beta Was this translation helpful? Give feedback.
React Query does this automatically by tracking and sharing promises via the query key. So if 3 requests to fetch the same query are made close to each other, the first will actually fire, create a promise, and the next two will use the promise created by the first. One request, one promise, three promise resolutions.