What's a good way to persist a single query for React Query

React query provides a persisted query client for persisting query results, but it seems to be for the whole app. What's a good way to persist a query result for a single query? (Using Nextjs + TRPC)
3 Replies
tylerlaws0n
tylerlaws0n4mo ago
I might not understand the question, but the query client exists to persist query results. So if your query key is consistent, the query client dedupes the requests if they are called in more than one component, so you can feel free to call that same query in whatever component you'd like to call it without fear of over querying. This is a major reason you'd use react query to begin with.
若帆 Leo
若帆 LeoOP4mo ago
I mean persist to the localStorage or sth
若帆 Leo
若帆 LeoOP4mo ago
persistQueryClient | TanStack Query React Docs
This is set of utilities for interacting with "persisters" which save your queryClient for later use. Different persisters can be used to store your client and cache to many different storage layers. Build Persisters
Want results from more Discord servers?
Add your server