Use React component in Astro
First run npx astro add react
Then create components/Test.jsx
export default function Test(props) {
return <p>test</p>
}
Now in a .astro
component import it:
import Test from '../components/Test'
and in its “JSX” include it:
<Test />
Done!
One gotcha: React components are rendered server-side, not client side, unless you add client:load
to them:
<Test client:load />
→ Here's my latest YouTube video
→ Get my React Beginner's Handbook
→ I wrote 17 books to help you become a better developer, download them all at $0 cost by joining my newsletter
→ JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025