Integrations: Passing Astro components to React components

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


In an Astro site page I wanted to add some bit of interactivity, and chose React.

I created the component, and inside it I had a pro state variable that was true or false and showed different things based on this state:

import { useState } from 'react'

export default function TabBar() {
  const [pro, setPro] = useState(false)

	return (
    <div>
      {pro ? <p>pro</p> : <p>free</p>}
    </div>
  )
}

and I used it like this:

<TabBar client:load />

(client:load otherwise it’s server-rendered at build time and not interactive).

So far so good.

But I wanted to pass multiple Astro components to this, so here’s what I did:

<TabBar client:load>
  <div slot='free'>
    <Free />
  </div>
  <div class='pt-2 mb-20' slot='pro'>PRO</div>
</TabBar>

Inside the React component, those slots are available through {props.pro} and {props.free}.

import { useState } from 'react'

export default function TabBar(props) {
  const [pro, setPro] = useState(false)

	return (
    <div>
      {pro ? props.pro : props.free}
    </div>
  )
}

Lessons in this unit:

0: Introduction
1: Client-side routing and view transitions
2: View Transitions and Dark Mode
3: Adding React Framer Motion animations to an Astro site - react - astro
4: Use React component in Astro - astro - react
5: ▶︎ Passing Astro components to React components
6: htmx and Astro View Transitions
7: htmx forms and Astro View Transitions