Skip to content
Discussion options

You must be logged in to vote

I see Pinia stores as a Reactive Service.

Let's remove Pinia from the equation for a sec, how would we manage the state out of Vue components?

With the reactive() object and using an instance of a class (the service):

class AuthenticationService {
  public isAuthenticated: boolean = false
  public user: AuthenticatedUser | null = null
  
  public login(email: string, password: string): Promise<void> {
     // API call
     this.isAuthenticated = true
     this.user = data.value
  }
}

const authenticationService = new AuthenticationService()
export const useAuthenticationService = () => reactive(authenticationService)

So, translating that logic into Pinia, the Pinia store actions represen…

Replies: 1 comment

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