Not sure about getContext. I vaguely recall looking into it and figuring out that getContext expects to be called as part of a render cycle of a component tree, which you canβt easily fake.
If youβre comfortable with relying on internal APIs like $on then one thing you could do is use the tutorial view for context (svelte.dev/tutorial/context-api). Choose JS output and explore the JS code that Svelte products for your component. Dig through to learn how setContext and getContext work. It might give you a solution. Failing that, use the Svelte source on GitHub. Let me know if you figure something out--Iβd be interested to know.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Glad to hear it worked! π
Not sure about
getContext
. I vaguely recall looking into it and figuring out thatgetContext
expects to be called as part of a render cycle of a component tree, which you canβt easily fake.If youβre comfortable with relying on internal APIs like
$on
then one thing you could do is use the tutorial view for context (svelte.dev/tutorial/context-api). ChooseJS output
and explore the JS code that Svelte products for your component. Dig through to learn howsetContext
andgetContext
work. It might give you a solution. Failing that, use the Svelte source on GitHub. Let me know if you figure something out--Iβd be interested to know.