Svelte exposes context functions from the svelte
package. To make data available down the component tree, use setContext
with a key and a value.
To read context from a parent component, use getContext
.
<script>
import { setContext } from 'svelte';
setContext('theme', 'light');
</script>
<!-- … -->
<script>
import { getContext } from 'svelte';
const theme = getContext('theme');
</script>
<!-- … -->