Skip to content

Instantly share code, notes, and snippets.

@pferreirafabricio
Created August 5, 2023 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pferreirafabricio/283b7a6ae4b96c7c72c9b259abb8a4b0 to your computer and use it in GitHub Desktop.
Save pferreirafabricio/283b7a6ae4b96c7c72c9b259abb8a4b0 to your computer and use it in GitHub Desktop.
πŸ—‘ Basic logic to reset all Pinia stores at same time
import { defineStore, getActivePinia } from "pinia";
const activePinia = getActivePinia();
if (!activePinia) return;
Object.entries(activePinia.state.value).forEach(([storeName, state]) => {
console.debug("Resetting store", storeName);
const storeDefinition = defineStore(storeName, state);
const store = storeDefinition(activePinia);
store.$reset();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment