T
TanStack2y ago
multiple-amethyst

Persist some parts of the queryCache to localstage

I have a pretty basic shoppinglist app where data is split it ints volatility: ingredients and recipes change infrequently, while the shoppinglist itself does changes often. Is it possible to hold the recipes and ingredients in local storage for a long time (e.g 7d) but prevent the shoppinglist from being persisted that long? Since I didn't see anything obvious in the queryClient or persister, I think the easiest choice is to have 2 queryClients differenty configured, one "long term" and one "short term"? The long term one would have proper localStorage persistence. Is this advisable? Am I inadvertenly walking into a trap? Any alternatives?
8 Replies
rival-black
rival-black2y ago
You can filter down what to persist with the PersistQueryClientProvider With the dehydrateOptions
multiple-amethyst
multiple-amethystOP2y ago
Cool yeah, that lets make make a decision based on the key. I guess due to how the typesystem is setup, there is no way to set an option on the query itself?
rival-black
rival-black2y ago
that's what the new experimental_createPersister is for. you can pass it to a single query and then this one will be persisted on its own
multiple-amethyst
multiple-amethystOP2y ago
Oh very interesting! I've annoyingly now hit the next wall that I saw described in a length github thread: I have a login mutation that calls setQueryData(...) within onSuccess :/
multiple-amethyst
multiple-amethystOP2y ago
GitHub
setQueryData() should be persisted too, right? · Issue #6310 · Ta...
Describe the bug I'm using the new experimental_createPersister like this: import { experimental_createPersister, type AsyncStorage } from "@tanstack/query-persist-client-core"; impor...
rival-black
rival-black2y ago
Yes, we're discussing how this should be handled. Feel free to provide your thoughts on the issue
multiple-amethyst
multiple-amethystOP2y ago
Are unqualified opinions welcome to? I think most had been said. I can give insight from an unknowing user 🤷‍♂️
rival-black
rival-black2y ago
sure I mean you have a use-case, so it would be good to hear how you would like it to work 🙂

Did you find this page helpful?