Skip to content

Is it sensible to merge values from localStorage right in the state() method? #821

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

You must be logged in to vote

I would say that, in general, merging everything from a localstorage value to the state will be more trouble than benefit. I recommend you to instead use https://vueuse.org/core/uselocalstorage/#uselocalstorage:

defineStore('id', {
  state: () => ({
    someSavedVariable: useLocalStorage(key, initialValue)
    // other
  })
})

// setup store
defineStore('id', () => {
  const someSavedVariable = useLocalStorage(...)
  // ...
})

I would recommend you to share more about why you need to use local storage and people will more likely to be able to help you on this one 🙂
The Discord chat should also be a nice place to ask this kind of question as it might go a bit beyond pinia itself

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants