@ -54,3 +54,25 @@ In fact, you might use the two together. Since context is not reactive, values t
```js
```js
const { these, are, stores } = getContext(...);
const { these, are, stores } = getContext(...);
```
```
## `getContext()` must be called during component initialisation
You may find this feature useful. However, remember to call `getContext()` during component initialisation! This means you can only use it directly in the `<script>` tag (for a `.svelte` file), not in any function. For example, this will work:
```js
import { getContext } from 'svelte';
const map = getContext('map');
```
While this will not:
```js
import { getContext } from 'svelte';
onMount(() => {
const map = getContext('map'); // will trigger an error!
});
```
You may find it work in some old Svelte versions, but it won't work for current versions of Svelte.