]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: hydrate example
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 Oct 2021 14:43:18 +0000 (16:43 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 Oct 2021 14:43:18 +0000 (16:43 +0200)
packages/pinia/src/types.ts

index 47376b99ed9b20d386f7ecd913493728fc94fd47..05dd5afb520387f1bafb01257873ba859cd44edf 100644 (file)
@@ -651,8 +651,25 @@ export interface DefineStoreOptions<
     >
 
   /**
-   * Allows hydrating the store during SSR when there is an available state in
-   * pinia.state.
+   * Allows hydrating the store during SSR when complex state (like client side only refs) are used in the store
+   * definition and copying the value from `pinia.state` isn't enough.
+   *
+   * @example
+   * If in your `state`, you use any `customRef`s, any `computed`s, or any `ref`s that have a different value on
+   * Server and Client, you need to manually hydrate them. e.g., a custom ref that is stored in the local
+   * storage:
+   *
+   * ```ts
+   * const useStore = defineStore('main', {
+   *   state: () => ({
+   *     n: useLocalStorage('key', 0)
+   *   }),
+   *   hydrate(storeState, initialState) {
+   *     // @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826
+   *     storeState.n = useLocalStorage('key', 0)
+   *   }
+   * })
+   * ```
    *
    * @param storeState - the current state in the store
    * @param initialState - initialState