From 5f4d2d5ec87e2440c20714eb524f7d3cadd70b1f Mon Sep 17 00:00:00 2001 From: vages Date: Sat, 3 Aug 2019 13:17:33 +0000 Subject: [PATCH] Explain difference between contexts and stores I had a problem understanding why you would want to use a context when you can just use a store. This is what I've gathered after reading a bit about them. --- .../tutorial/15-context/01-context-api/text.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/site/content/tutorial/15-context/01-context-api/text.md b/site/content/tutorial/15-context/01-context-api/text.md index ef146772c5..e6f6d25dac 100644 --- a/site/content/tutorial/15-context/01-context-api/text.md +++ b/site/content/tutorial/15-context/01-context-api/text.md @@ -35,6 +35,20 @@ The markers can now add themselves to the map. > A more finished version of `` would also handle removal and prop changes, but we're only demonstrating context here. +## Contexts vs. stores + +Contexts and stores seem similar. They differ in that stores are available to *any* part of an app, while a context is only *available to a component and its descendants*. This can be helpful if you want to use several copies of a component without the state of one interfering with the state of the others. + +Try making a copy of the Map component in `App.svelte` to see how this works. Replace the style tag in `Map.svelte` with the following to show both maps: + +```html + +``` ## Context keys