From: Eduardo San Martin Morote Date: Thu, 7 Jan 2021 16:20:07 +0000 (+0100) Subject: refactor: remove getRootState X-Git-Tag: v2.0.0-alpha.7~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d5417bb8377e5467fa94cb355696ec8446628eb1;p=thirdparty%2Fvuejs%2Fpinia.git refactor: remove getRootState BREAKING_CHANGE: Since req as a parameter was replacetd with `pinia`, `getRootState` is no longer necessary. Replace it with `pinia.state.value` to read the root state` --- diff --git a/README.md b/README.md index e4b938ea..d11bbc09 100644 --- a/README.md +++ b/README.md @@ -294,7 +294,7 @@ router.beforeEach((to) => { To hydrate the initial state, you need to make sure the rootState is included somewhere in the HTML for Pinia to pick it up later on: ```js -import { createPinia, getRootState } from 'pinia' +import { createPinia } from 'pinia' // retrieve the rootState server side const pinia = createPinia() const app = createApp(App) @@ -302,16 +302,23 @@ app.use(router) app.use(pinia) // after rendering the page, the root state is build and can be read -getRootState() // serialize, escape, and place it somewhere on the page, for example, as a global variable +// serialize, escape (VERY important if the content of the state can be changed +// by the user, which is almost always the case), and place it somewhere on +// the page, for example, as a global variable. +JSON.stringify(pinia.state.value) ``` -On client side, you must tell pinia how to read that variable: +On client side, you must hydrate pinia's state before calling any `useStore()` function. For example, if we serialize the state into a `