Comments (6)
yes, it breaks current instance because it creates one itself to outlive component scoped for the state, but creating it outside of a component, by calling useStore
for the first time, doesn't break any current instance 🙂
from pinia.
Yeah, this is a limitation that needs to wait for vuejs/rfcs#212. For now, it's necessary to call the useStore
function at the end of setup
or call pinia.store(useStore)
for each store in your main.js file (it will also remvoe the code splitting)
from pinia.
I am wondering whether there is an easier way to call pinia.store for all stores. Currently this feels like the biggest issue for me as moving things around setup function does not make it readable or maintainable. Also not always possible and required multiple instances of pinia stores around one setup function.
In some compiled language I would use reflection to register stuff like that within an assembly. Doesn't seem like the mentioned RFC got a lot of positive feedback 😰
from pinia.
It's annoying for me too. The easiest workaround is to import all stores in your main.js file and call pinia.store(useStore)
to instantiate them.
The RFC will go through a way or another because there is a need for it
from pinia.
Thanks I will end up doing that. Generally is this the same reason why this is happening?
const firstInstance = getCurrentInstance(); //resolves properly
const userEditStore = useSomeStore();
const secondInstance = getCurrentInstance(); //always null
This seems to be the reason why useVuelidate which is internally calling getCurrentInstance is failing. I wanted to bind vuelidate directly to my store state so I will just import all stores at start like you mentioned.
from pinia.
I use pinia^2.0.13 in vue2, and postinstall npx vue-demi-switch 2, alll ok.
but when i use onBeforeMount or others Lifecycle in setup, how can i resolve it?
from pinia.
Related Issues (20)
- Pinia playground doesn't work with option store HOT 2
- docs(fa): add persian documentation HOT 1
- Patching store returns compile error in vscode
- doc code font can be normal ?
- Caching getters on server with Nuxt2 is not working as expected HOT 3
- in ts getters using 'this' doesn't affect
- Issue with typescript
- undefined is not an object (evaluating 'pinia._s.has'),TypeError, useStore
- `mapState()` not working with Vue 3.4 HOT 4
- Pinia Nuxt module breaks the `createTestingPinia` helper in tests HOT 6
- pinia running Browser extensions not work HOT 2
- Reactivity loss when using pinia with @vue/compat HOT 4
- Combining setup stores results in a store with type never. HOT 2
- pinia tries to import default export from vue package
- When a computed ref is present in the setup function of a Pinia store, using mapState may lead to typing errors. HOT 3
- `storeToRefs` loses the original typings of refs/computeds in a setup store, "generalizes" them instead
- The document file "/interfaces/pinia.SetupStoreDefinition.md" is missing. HOT 1
- Unable to test setup store actions with watcher HOT 1
- Component not updating (even though data is updated in devtools) when using external class to change data in Pinia Store [Nuxt 2/Bridge]
- `_UnwrapAll` not working when pinia stores is from npm package HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pinia.