Skip to content

Questions about the new setup syntax with effectScope() #623

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

You must be logged in to vote

I'm glad you are enjoying Pinia!

No syntax is recommended over the other. The setup syntax makes it sometimes much easier to write stores, especially when using other composition functions.

The options api has slightly better devtools support because it's able to group state changes within actions.

Note you can call any composable inside of state() since it's ran inside an effectScope():

defineStore('route', {
  state() {
    const route = useRoute()
    // could even be return route
    return {
      path: useRoutePath()
    }
  }
})

Replies: 2 comments 6 replies

Comment options

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

@GoudekettingRM
Comment options

@posva
Comment options

@StefanFlaschko
Comment options

@ramsesmoreno
Comment options

Answer selected by holtergram
Comment options

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants