Search code examples
reactjsastrojs

Use ReactJs components in a tsx components in Astro


I have an astro based framework and I wondering if the following is possible: I have an .astro page with this code

<BaseLayout title={`My title`}>
  <main>
    <Navbar client:only />
    <div class="container mt-5">
      <div class="my-5">
        <ProductPageDetail
          
        />
      </div>
    </div>
    <Footer />
  </main>
</BaseLayout>

I wonder if in ProductPageDetail (an astro component) I can use reactjs client side code.

I tried to add this in my component

<AddToCart client:only></AddToCart>

inside my ProductPageDetail but I have this error

Type '{ "client:only": true; }' is not assignable to type 'IntrinsicAttributes'.

So my question is how to have a client rendered component inside a server side rendered component? Is this even possible? I put some console.log("test") inside my AddToCart but I see the message server side.


Solution

  • The client:only directive requires the component's framework as a value

    <SomeReactComponent client:only="react" />
    <SomePreactComponent client:only="preact" />
    <SomeSvelteComponent client:only="svelte" />
    <SomeVueComponent client:only="vue" />
    <SomeSolidComponent client:only="solid-js" />