From: Eduardo San Martin Morote Date: Sun, 24 Jul 2022 16:15:23 +0000 (+0200) Subject: docs: review X-Git-Tag: @pinia/nuxt@0.3.1~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a32163f6f8bb7e94e15638b9282d0457877c7c18;p=thirdparty%2Fvuejs%2Fpinia.git docs: review Close #1471 --- diff --git a/packages/docs/core-concepts/state.md b/packages/docs/core-concepts/state.md index 97336861..686670bb 100644 --- a/packages/docs/core-concepts/state.md +++ b/packages/docs/core-concepts/state.md @@ -192,15 +192,18 @@ cartStore.$patch((state) => { The main difference here is that `$patch()` allows you to group multiple changes into one single entry in the devtools. Note **both, direct changes to `state` and `$patch()` appear in the devtools** and can be time traveled (not yet in Vue 3). -## Merging the `state` +## Replacing the `state` -You can merge a new object into a state of store by setting its `$state` property: +You **cannot exactly replace** the state of a store as that would break reactivity. You can however _patch it_: ```js +// this doesn't actually replace `$state` store.$state = { counter: 24 } +// it internally calls `$patch()`: +store.$patch({ counter: 24 }) ``` -You can also replace the whole state of your application by changing the `state` of the `pinia` instance. This is used during [SSR for hydration](../ssr/#state-hydration). +You can also **set the initial state** of your whole application by changing the `state` of the `pinia` instance. This is used during [SSR for hydration](../ssr/#state-hydration). ```js pinia.state.value = {}