QwikDev / astro

Qwik + Astro integration
209 stars 13 forks source link

Any good example of Qwik.useContext in Astro project? #121

Closed sx-motive closed 4 months ago

sx-motive commented 4 months ago

After reading the approach used in qwik, I understood the architectural limitations. But I still have a question that if I can't use global storage, how can I pass values to child elements via useContext?

The example from the documentation works fine if you pass a jsx component to . But in real projects between these components always will be astro component layers. And if I pass in an astro component (which contains my child jsx elements inside), then using context becomes impossible.

Are there any examples of using context in Astro?

thejackshelton commented 4 months ago

Hey @sx-motive!

The benefit of context, is that even if your component is passed between an Astro component, that component should still have access to the context.

<RootComp>
  <AstroComp>
     <QwikComp />
  </AstroComp>
</RootComp>

That should work.

This is a guess here, but if you were passing the Qwik component directly inside the Astro component rather than a slot, then the root component's context would not be able to understand the embedded Qwik component in the Astro component.

There are currently discussions in Qwik about better global state management from the core team.

For now we have context and custom events. I will update this issue if there is another alternative down the road here.

thejackshelton commented 4 months ago

Closing. If there's any sort of issue feel free to open a new one 👍