Getting Started with an Astro App using React Components

This guide shows you how to set up an Astro application and integrating Syncfusion® React components.

What is Astro?

Astro is a modern web framework for building fast, content-driven sites. It focuses on performance and is ideal for static websites, blogs, and documentation. Developers use Astro to create lightweight, highly optimized projects with ease.

Prerequisites

Create an Astro project

To create a new Astro project, use the following command:

After running the command, follow the prompts to configure your Astro project:

Add React support to Astro project

React is one of the most popular UI libraries that can be seamlessly integrated with Astro projects. Follow these steps to add React support to your Astro project.

1. Install React and Astro React packages

Install the necessary React packages and the Astro React packages:

2. Integrate React with Astro

Open your astro.config.mjs file and add the React integration code:

Install Syncfusion® React packages

Syncfusion® React components are available on npmjs.com. To use the React Message component, install the @syncfusion/react-notifications package:

Add the Syncfusion® React component

To use the Message component in your application, create a new file named message.tsx in the src/components/ directory. Then, add the following sample code to include the Message in your Astro project.

Import Syncfusion® CSS styles

Import themes for our React components using CSS or SASS from npm packages. For details on built-in themes and usage, refer to the themes topic.

In this guide, we apply the Material theme with CSS styles in the src/components/message.tsx file:

Ensure CSS styles are imported in the correct dependency order.

Display the message component in the Astro page

To show the Message component on your page, import and place it in your src/pages/index.astro file:

Use client:only="react" for Syncfusion® React components because these components depend entirely on React’s runtime and cannot be server-rendered by Astro.

Run the project

To run the project, use the following command:

The output will appear as follows: