HelpBot Assistant

How can I help you?

Getting started with React AppBar component

6 Feb 20262 minutes to read

This section explains how to create a simple AppBar, and configure its available functionalities in React.

Dependencies

The following dependencies are required to use the AppBar component in an application. These packages provide core functionalities and UI controls for the AppBar.

|-- @syncfusion/ej2-react-navigations
    |-- @syncfusion/ej2-react-base
    |-- @syncfusion/ej2-navigations
        |-- @syncfusion/ej2-base

Setup your development environment

To easily set up a React application, use create-vite-app, which provides a faster development environment, smaller bundle sizes, and optimized builds compared to traditional tools like create-react-app. For detailed steps, refer to the Vite installation instructions. Vite sets up your environment using JavaScript and optimizes your application for production.

Note: To create a React application using create-react-app, refer to this documentation for more details.

To create a new React application, run the following command.

npm create vite@latest my-app

To set-up a React application in TypeScript environment, run the following command.

npm create vite@latest my-app -- --template react-ts
cd my-app
npm run dev

To set-up a React application in JavaScript environment, run the following command.

npm create vite@latest my-app -- --template react
cd my-app
npm run dev

Adding Syncfusion® packages

All the available Essential® JS 2 packages are published in npmjs.com public registry.

To install AppBar component, use the following command

npm install @syncfusion/ej2-react-navigations --save
npm install @syncfusion/ej2-react-buttons --save

The above command installs AppBar dependencies
which are required to render the component in the React environment.

Adding Style sheet to the Application

Add AppBar component’s styles as given below in App.css.

@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";

Add AppBar to the project

Create the AppBar component in the application by adding the following code snippet to the src/App.tsx file.

import { AppBarComponent } from "@syncfusion/ej2-react-navigations";
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import * as React from "react";

const App = () => {
  return (
    <div className='control-container'>
      <AppBarComponent colorMode="Primary">
        <ButtonComponent cssClass='e-inherit menu' iconCss='e-icons e-menu'></ButtonComponent>
        <span className="regular">React AppBar</span>
        <div className="e-appbar-spacer"></div>
        <ButtonComponent cssClass='e-inherit login'>FREE TRIAL</ButtonComponent>
      </AppBarComponent>
    </div>
  );
}

export default App;

Run the application

Run the npm run dev command in the console to start the development server. This command compiles code and serves the application locally, opening it in the browser.

npm run dev