]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: note about reset in setup stores
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 13 Feb 2023 09:00:08 +0000 (10:00 +0100)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Wed, 15 Feb 2023 09:52:57 +0000 (10:52 +0100)
packages/docs/core-concepts/state.md

index 6751ac3d37ecf75b4c5bca6d33bd678031f59698..82b754b9604e374901b1b909ade169b4ae3bf1a0 100644 (file)
@@ -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
 
 <VueSchoolLink