Getting Started
22 Nov 20234 minutes to read
The following section explains how to create a simple Badge component using styles and Badge’s basic usage.
Dependencies
Install the following required dependent package to render the Badge
component.
|-- @syncfusion/ej2-notifications
Installation and configuration
You can use Create-react-app
to setup the applications. To install create-react-app
run the following command.
npm install -g create-react-app
To set-up a React application in TypeScript environment, run the following command.
```
npx create-react-app my-app --template typescript
cd my-app
npm start
```
To set-up a React application in JavaScript environment, run the following command.
```
npx create-react-app my-app
cd my-app
npm start
```
## Adding Syncfusion packages
All the available Essential JS 2 packages are published in [`npmjs.com`](https://www.npmjs.com/~syncfusionorg) public registry.
To install `Badge` component, use the following command
```bash
npm install @syncfusion/ej2-notifications --save
```
## Adding CSS Reference
Badge CSS files are available in the `ej2-notifications` package folder. Import the Badge component's required CSS references as follows in `src/App.css`.
```css
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-notifications/styles/material.css";
```
> We can also use [CRG](https://crg.syncfusion.com/) to generate combined component styles.
## Initialize the Badge Component
Add an HTML span element with `e-badge` class inside any wrapper element (h1) into your return method.
```ts
import * as React from 'react';
import * as ReactDOM from "react-dom";
import './App.css';
function App() {
return (
, document.getElementById("element"));
```
## Run the application
Run the application in the browser using the following command:
```
npm start
```
Output will be as follows:
## See Also
[Types of Badge](./types)
Badge Component New
22 Nov 20234 minutes to read
); } export default App; ReactDOM.render(import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
return (<h1>Badge Component <span className="e-badge e-badge-primary">New</span></h1>);
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
return (
<h1>Badge Component <span className="e-badge e-badge-primary">New</span></h1>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 React Badge Sample</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/23.2.4/ej2-notifications/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<link rel="stylesheet" href="index.css" />
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='element'>
<div id='loader'>Loading....</div></div>
</body>
</html>