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 />
→ Get my React Beginner's Handbook
I wrote 21 books to help you become a better developer:
- HTML Handbook
- Next.js Pages Router Handbook
- Alpine.js Handbook
- HTMX Handbook
- TypeScript Handbook
- React Handbook
- SQL Handbook
- Git Cheat Sheet
- Laravel Handbook
- Express Handbook
- Swift Handbook
- Go Handbook
- PHP Handbook
- Python Handbook
- Linux Commands Handbook
- C Handbook
- JavaScript Handbook
- Svelte Handbook
- CSS Handbook
- Node.js Handbook
- Vue Handbook
Also, 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