Skip to content

How to dynamically decide which imported store i have to use from another store? #2586

Discussion options

You must be logged in to vote

If addItem function can be asynchronous, you can import the stores dynamically using template literal:

https://stackblitz.com/edit/vitejs-vite-7jamvv?file=src%2Fstores%2Fmain.store.js

Otherwise:

const stores = {
  WEBCAM: useArticleWebcamStore,
  LAPTOP: useArticleLaptopStore,
  // Add more
}

 function addItem(type, name) {
   const store = stores[type]()
   store.addNewItem(name)
  }

Wish you lots of health, peace, and success. 👋🔥💚

Replies: 1 comment

Comment options

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