Skip to content

Subscribe / watch from inside a store? #794

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

You must be logged in to vote

Use a setup store instead, it's like a component but without a template:

defineStore('id', () => {
  const userId = ref(0)
  // other state properties
  // ...
  watch(userId, doStuff)
  function doStuff() {
    // ...
  }

  // expose anything you need
  return { state }
})

Replies: 17 comments 34 replies

Comment options

You must be logged in to vote
13 replies
@WilliamStam
Comment options

@theoephraim
Comment options

@SetsuikiHyoryu
Comment options

@hyrumwhite
Comment options

@hyrumwhite
Comment options

Answer selected by sockenklaus
Comment options

You must be logged in to vote
5 replies
@posva
Comment options

@hipertracker
Comment options

@elijah-shady
Comment options

@whitespacecode
Comment options

@Uraharadono
Comment options

Comment options

You must be logged in to vote
3 replies
@sockenklaus
Comment options

@kissu
Comment options

@lachlanmcdonald
Comment options

Comment options

You must be logged in to vote
3 replies
@kissu
Comment options

@quantuminformation
Comment options

@kissu
Comment options

This comment was marked as spam.

@quantuminformation
Comment options

@kissu
Comment options

Comment options

You must be logged in to vote
0 replies

This comment has been hidden.

@HuyPham55
Comment options

Comment options

You must be logged in to vote
4 replies
@Sjoerd82
Comment options

@smerchkz
Comment options

@Sjoerd82
Comment options

@nvmnghia
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@mamitry
Comment options

@danbars
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

Comment options

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