From: Eduardo San Martin Morote Date: Mon, 13 Feb 2023 09:00:08 +0000 (+0100) Subject: docs: note about reset in setup stores X-Git-Tag: @pinia/nuxt@0.4.7~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9b40c0db26032c29487a60ada7b663a0fcc168d;p=thirdparty%2Fvuejs%2Fpinia.git docs: note about reset in setup stores --- diff --git a/packages/docs/core-concepts/state.md b/packages/docs/core-concepts/state.md index 6751ac3d..82b754b9 100644 --- a/packages/docs/core-concepts/state.md +++ b/packages/docs/core-concepts/state.md @@ -88,7 +88,7 @@ Note you cannot add a new state property **if you don't define it in `state()`** ## Resetting the state -You can _reset_ the state to its initial value by calling the `$reset()` method on the store: +In [Option Stores](/core-concepts/index.md#option-stores), you can _reset_ the state to its initial value by calling the `$reset()` method on the store: ```js const store = useStore() @@ -96,6 +96,22 @@ const store = useStore() store.$reset() ``` +Internally, this calls the `state()` function to create a new state object and replaces the current state with it. + +In [Setup Stores](/core-concepts/index.md#setup-stores), you need to create your own `$reset()` method: + +```ts +export const useCounterStore = defineStore('counter', () => { + const count = ref(0) + + function $reset() { + count.value = 0 + } + + return { count, $reset } +}) +``` + ### Usage with the Options API