How to choose between Store and Context?
I've gathered that a store can reside in its own file and be imported in multiple locations, acting as a shared state. Given this, why would I opt for a context when a store seems capable of handling the task?
Whether it's for theming or authentication status, a store seems apt. Is there an advantage to using a context, or some trade-offs or crucial factors I might be overlooking?
3 Replies
in my understanding,
context
should be used for a scoped state, and can assert a owner to cleanup computations. if there just a global createStore
without computations, they are the samethey are completely different tools and can be used together. Context is simply a mechanism for sharing an object within a sub tree (dependency injection). Store is a nested tree of signals. Since context doesn’t give you reactivity, you might want to put a store in a context so your context can be dynamic.
Ok thank you both for your input. That was my understanding but I wanted to make sure I got it right.