#React
1 messages · Page 1 of 1 (latest)
Hi @pallid glacier. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To include React in your Astro project, you need to install the official React integration. Astro provides a straightforward way to add React support through its integration system.
Installing React in Astro
You can add React to your Astro project using the astro add command, which automates the setup process:
# Using npm
npx astro add react
# Using pnpm
pnpm astro add react
# Using Yarn
yarn astro add react
This command will:
- Install the necessary dependencies (
@astrojs/react,react, andreact-dom) - Update your
astro.config.mjsfile to include the React integration - Configure TypeScript properly if you're using it
Manual Installation
If you prefer to set things up manually, you can follow these steps:
-
Install the required packages:
npm install @astrojs/react react react-dom @types/react @types/react-dom -
Add the React integration to your
astro.config.mjsfile:import { defineConfig } from 'astro/config'; import react from '@astrojs/react'; export default defineConfig({ integrations: [react()], }); -
If using TypeScript, update your
tsconfig.json:{ "extends": "astro/tsconfigs/strict", "include": [".astro/types.d.ts", "**/*"], "exclude": ["dist"], "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "react" } }
After installation, you can use React components in your Astro files by importing them and adding a client directive to enable interactivity:
---
import MyReactComponent from '../components/MyReactComponent.jsx';
---
<MyReactComponent client:load />
The client directive (like `client:load`) is necessary to hydrate your React components for interactivity on the client side.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@pallid glacier Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Let me check the knowledge base for you again. One moment! :books:
I apologize for misunderstanding your question. You're specifically asking about the React Compiler (also known as React Forget), not just React integration in Astro.
Based on the knowledge sources provided, there is no specific information about integrating React Compiler with Astro. The documentation covers how to add React itself to Astro projects, but doesn't mention React Compiler specifically.
The React integration in Astro (@astrojs/react) allows you to use React components in your Astro project, but the knowledge sources don't contain information about configuring or enabling React Compiler within this integration.
If you're interested in using React Compiler with Astro, you might need to check the latest Astro documentation or the React Compiler documentation for compatibility information, as this appears to be outside the scope of the provided knowledge sources.