beyonk-group / svelte-mapbox

MapBox Map and Autocomplete components for Svelte (or Vanilla JS)
MIT License
346 stars 61 forks source link

getContext for custom svelte map component #67

Open JamesForan opened 2 years ago

JamesForan commented 2 years ago

I am currently experimenting with using svelte-mapbox in my project.

As part of this, I have built a custom 'mapLine.svelte' component.

I am trying to getContext in the following way:

import { contextKey } from '@beyonk/svelte-mapbox/src/lib/mapbox' const { getMap } = getContext(contextKey);

This is not working as expected though. For this to work, I have to set contextKey to a "string" for it to successfully getContext in svelte.in the mapbox.js file I am importing.

mapbox.js file updated from: const contextKey = {} export { contextKey }

to const contextKey = "contextKey" export { contextKey }

Keen to understand the correct way to do this.

The other thing I tried was to set the contextKey in my project, and pass this in as a parameter to @beyonk Map.svelte component. this also worked..

What is the recommended way to achieve custom components with this library?

hburrichter commented 1 year ago

I have the same Problem. Did you solve it, @JamesForan ?