Skip to content

Clear all stores #693

Sep 29, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

There is no way to do it directly as most of the time a user disconnecting doesn't mean all stores to get $reset() and some setup based stores cannot be $reset().

You can however create a plugin that holds a reference to every store created within a map or array and expose a function that removes them:

let stores = []
pinia.use(({ store }) => {
  stores.push(store)
})

function resetAllStores() {
  stores.forEach(store => {
    store.$reset()
  })
  stores = []
})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Lord-Y
Comment options

Answer selected by Lord-Y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants