T
TanStack13mo ago
exotic-emerald

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
metropolitan-bronze
metropolitan-bronze13mo 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?
exotic-emerald
exotic-emeraldOP13mo 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.
metropolitan-bronze
metropolitan-bronze13mo 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.
From An unknown user
From An unknown user
exotic-emerald
exotic-emeraldOP13mo ago
Perfect, thanks!

Did you find this page helpful?