Skip to content

How to fully reset pinia(s)? #587

Jul 28, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

You can add this with a plugin:

pinia.use(({ store, pinia }) => {
  pinia.storesToReset = pinia.storesToReset || new Set()
  pinia.storesToReset.add(store)

  if (!pinia.reset) {
    pinia.reset = () => {
	  pinia.storesToReset.forEach(store => store.$reset())
    }
  }
})

It can also be typed by extending Pinia and you could also add a custom Option to skip resetting: https://pinia.esm.dev/core-concepts/plugins.html#adding-new-options

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@0x009922
Comment options

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