Feature request: refetchOnUnmount?
For any team members here, has adding refetchOnUnmount been discussed at any point? Think we'll see this in Query's future?
4 Replies
crude-lavender•10mo ago
I'm gonna be a bit presumptuous and say that sounds strange. unmounted queries become inactive if there's no other observers and will be garbage collected out. This seems to run counter to the design of it. Why would you want query to do this?
deep-jadeOP•10mo ago
I have a SuggestedUsers component that I don't want fetching on mount or during its life cycle. Rather, I want the query fetched on unmount, so that the next time this component mounts its data is fresh.
crude-lavender•10mo ago
That sounds like you want to prefetch the query? https://tanstack.com/query/latest/docs/framework/react/guides/prefetching
TanStack | High Quality Open-Source Software for Web Developers
Headless, type-safe, powerful utilities for complex workflows like Data Management, Data Visualization, Charts, Tables, and UI Components.

deep-jadeOP•10mo ago
Perfect, thanks!