Mastering Pinia @masteringpinia.com · Apr 29

A community member asked us: "We’re migrating from Vuex to Pinia and are debating where to place business logic. Should stores just handle setting and retrieving reactive state, or is it fine to keep logic like transforming API responses in the store? ..." 1/3 🧵👇

1 likes 2 replies

?

Replies

Mastering Pinia · Apr 29

...I originally leaned that way, but now I’m thinking it may be cleaner to keep it in the store, unless the logic is reused elsewhere." Here is our answer: 🤓 You can see stores as Services if that helps. If you are doing SSR, make sure to handle the serialization. 3/3

Mastering Pinia · Apr 29

...For example, when fetching users, we loop through the response, instantiate `User` objects, and store them in a map. Would it be better to offload that transformation to a service?... 2/3