Choosing between a Svelte context and a Svelte store
The Svelte context and Svelte store are designed for very different use cases.
Here’s a recap: the Svelte context helps pass data from a parent component to all descendent components, while a Svelte store helps make data reactive across multiple Svelte components.
Although both the Svelte context and Svelte store are meant to pass data across Svelte components, they are designed for different use cases. So, choosing when to use a Svelte context and Svelte store is never an either-or situation.
You can use either a Svelte context, a Svelte store, or both to pass the same data across Svelte components.
To decide which one to use, I’ve come up with a 2x2 decision matrix:
Figure 8.2: A decision matrix for choosing a Svelte store, a Svelte context, or both
In this 2x2 decision matrix, there are two dimensions: local-global and static-reactive.
Depending on the kind of data you...