]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: add increment function example
authoristiyak <tailoristiyak303@gmail.com>
Wed, 9 Feb 2022 09:45:05 +0000 (15:15 +0530)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 18 Feb 2022 23:03:44 +0000 (00:03 +0100)
packages/docs/core-concepts/index.md

index 03230718de96eb5313abbb7713107a2f72385635..ca702b779bd5a29e0fc44bc72bfe2cc6b1ea0923 100644 (file)
@@ -92,10 +92,41 @@ export default defineComponent({
 :::warning
 Extracting `actions` using `storeToRefs` will result in `actions` being `undefined`. To extract `actions` from the store, you should skip using `storeToRefs`
 
-```
-const store = useStore()
+```js
+import { storeToRefs } from 'pinia'
+import useCounterStore from '@/store/counter'
+
+export default defineComponent({
+    const store = useCounterStore()
+
+    const { counter, increment } = storeToRefs(store)
+
+    counter // 1
+
+    // ❌ This won't work because
+    // `storeToRefs` skips `actions` from the store
+    increment() // "undefined"
+
 
-const { fullName, age } = store
-const { logIn } = store
+    // if you want to only destructure `actions`
+    // from the store then don't use `storeToRefs`
+    const { increment } = store
+
+    increment() // works!
+    counter // 2
+})
 ```
 :::
+
+:::tip
+- **To extract only the properties from the store:**
+    - `const { counter } = counterStore`
+
+<br/>
+
+- **To extract only the actions from the store:**
+    - `const { increment, decrement } = counterStore`
+:::
+
+
+