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
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.
I mean persist to the localStorage or sth
Like https://tanstack.com/query/latest/docs/framework/react/plugins/persistQueryClient but if we can do it per query
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