Skip to content

Use React component in Astro

New Course Coming Soon:

Get Really Good at Git

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 />

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Read my Astro Tutorial on The Valley of Code
→ Get my React Beginner's Handbook
→ Read my full React Tutorial on The Valley of Code

Here is how can I help you: