S
SolidJS13mo ago
aryzing

How to clear a store?

From the docs, seems that setting a store's value explicitly to undefined will delete it from the store,
setStore({foo: undefined}) // foo is removed from store
setStore({foo: undefined}) // foo is removed from store
However, is there a way to clear them all in one go? If there are many keys, or the keys change, it's hard to ensure they're all getting deleted when they need to.
5 Replies
apollo79
apollo7913mo ago
I answered this here: https://discord.com/channels/722131463138705510/1173831851765411840/1174024744811634718 basically no straightforward way, but setStore(Object.keys(store), undefined) gets you there
aryzing
aryzingOP13mo ago
Appreciate the answer even if the question is a dupe, it didn't show up in the search results before posting this one. If useful, with TS would look like,
setState(Object.keys(state) as Array<keyof typeof state>, undefined);
setState(Object.keys(state) as Array<keyof typeof state>, undefined);
JCM
JCM13mo ago
I do setStore(reconcile({})) for that use case This is what the new doc seems to recommend https://docs.solidjs.com/references/api-reference/stores/using-stores#updating-stores
aryzing
aryzingOP13mo ago
Amazing, thank you!
bigmistqke
bigmistqke13mo ago
i didn't know you can do ['array', 'of', 'keys'] that's cool
Want results from more Discord servers?
Add your server