#How to clear a store?

8 messages · Page 1 of 1 (latest)

grand dragon
#

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

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.

dense oyster
#

basically no straightforward way, but setStore(Object.keys(store), undefined) gets you there

grand dragon
#

Appreciate the answer even if the question is a dupe, it didn't show up in the search results before posting this one.

grand dragon
#

If useful, with TS would look like,

setState(Object.keys(state) as Array<keyof typeof state>, undefined);
stuck mason
#

I do setStore(reconcile({})) for that use case

grand dragon
#

Amazing, thank you!