Skip to content

Reusing Nuxt server state on the client with a setup store #1213

Closed Answered by obulat
obulat asked this question in Help and Questions
Discussion options

You must be logged in to vote

I've found the solution for this problem in Pinia documentation: https://pinia.vuejs.org/cookbook/composables.html#ssr

The ref values that should not be re-initialized on the client side need to use skipHydration helper function:

import { defineStore, skipHydrate } from 'pinia'
import { useEyeDropper, useLocalStorage } from '@vueuse/core'

export const useColorStore = defineStore('colors', () => {
  const { isSupported, open, sRGBHex } = useEyeDropper()
  const lastColor = useLocalStorage('lastColor', sRGBHex)
  // ...
  return {
    lastColor: skipHydrate(lastColor), // Ref<string>
    open, // Function
    isSupported, // boolean (not even reactive)
  }
})

(The code is from the Compos…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@murobbani18
Comment options

Answer selected by obulat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants