doc: Add notes to stress call-context-during-initialisation (#5631)

pull/7738/head
Outvi V 5 years ago committed by GitHub
parent 87739dca48
commit e34b181092

@ -19,7 +19,7 @@ setContext(key, {
}); });
``` ```
The context object can be anything you like. Like [lifecycle functions](tutorial/onmount), `setContext` and `getContext` must be called during component initialisation; since `map` isn't created until the component has mounted, our context object contains a `getMap` function rather than `map` itself. The context object can be anything you like. Like [lifecycle functions](tutorial/onmount), `setContext` and `getContext` must be called during component initialisation. Calling it afterwards - for example inside `onMount` - will throw an error. In this example, since `map` isn't created until the component has mounted, our context object contains a `getMap` function rather than `map` itself.
On the other side of the equation, in `MapMarker.svelte`, we can now get a reference to the Mapbox instance: On the other side of the equation, in `MapMarker.svelte`, we can now get a reference to the Mapbox instance:

Loading…
Cancel
Save