stormy-gold
stormy-gold4h ago

Global refetch

Hi! I’m using Refine with a dataProvider that can change dynamically. I want all my resource lists to automatically refetch whenever the dataProvider changes.
2 Replies
kapa.ai
kapa.ai4h ago
Hi @khadhulu. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Short answer: there’s no built‑in “global refetch on dataProvider change” toggle in the docs. However, you can reliably force refetches using invalidate/refetch utilities: - If you know when the dataProvider changes, call useInvalidate to invalidate all queries for each resource (optionally per dataProviderName). This triggers refetches for affected lists. - Invalidate all states for a given data provider:
invalidate({ dataProviderName: "second-data-provider", invalidates: ["all"] });

invalidate({ dataProviderName: "second-data-provider", invalidates: ["all"] });

- Or invalidate lists for specific resources:
invalidate({ resource: "posts", invalidates: ["list"] });

invalidate({ resource: "posts", invalidates: ["list"] });

This is the documented way to programmatically refetch across hooks. [FAQ] - You can also call refetch from each page/hook (useList/useTable/useShow/etc.) if you have access to them, but invalidate is preferable for a global approach. [FAQ] Notes and related: - Multiple data providers require a default; you can pick providers per hook via dataProviderName or per resource via meta.dataProviderName. If the active provider changes, target the right dataProviderName in invalidate calls. [Multiple providers; Usage] If you need automatic refetches on backend data changes, consider integrating a Live Provider (realtime) so lists refetch on live events, independent of manual invalidation. [Realtime] Limitation: The knowledge sources don’t mention an automatic listener that refetches all resources when the top-level dataProvider object changes. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4h ago
<@236239059184386048> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?