- Dependencies
- Installation and configuration
- Adding syncfusion® packages
- Adding CSS reference
- Adding ListBox component
- Binding data source
- Run the application
Contact Support
Getting Started
8 May 20258 minutes to read
This section briefly explains how to create a simple ListBox component and configure its available functionalities in React.
Dependencies
The following list of dependencies are required to use the ListBox
component in your application.
|-- @syncfusion/ej2-react-dropdowns
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-data
|-- @syncfusion/ej2-react-base
|-- @syncfusion/ej2-dropdowns
|-- @syncfusion/ej2-lists
|-- @syncfusion/ej2-inputs
|-- @syncfusion/ej2-navigations
|-- @syncfusion/ej2-popups
|-- @syncfusion/ej2-buttons
Installation and configuration
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. You can choose the component that you want to install.
To install ListBox component, use the following command
npm install @syncfusion/ej2-react-dropdowns --save
Adding CSS reference
Import the ListBox component required CSS references as follows in src/App.css
.
/* import the ListBox dependency styles */
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-react-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-react-dropdowns/styles/material.css";
Adding ListBox component
Now, you can start adding ListBox component in the application. For getting started, add the ListBox component in src/App.tsx
file using following code.
Add the below code in the src/App.tsx
to initialize the ListBox.
import * as React from 'react';
import * as ReactDOM from "react-dom";
import { ListBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import './App.css';
function App() {
return (
// specifies the tag for render the ListBox component
<ListBoxComponent id='listbox'></ListBoxComponent>
);
}
export default App;
Binding data source
After initialization, populate the ListBox with data using the dataSource property. Here, an array of object is passed to the ListBox component.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ListBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import './App.css';
function App() {
// define the array of object
let data: { [key: string]: Object }[] = [
{ text: 'Hennessey Venom', id: 'list-01' },
{ text: 'Bugatti Chiron', id: 'list-02' },
{ text: 'Bugatti Veyron Super Sport', id: 'list-03' },
{ text: 'SSC Ultimate Aero', id: 'list-04' },
{ text: 'Koenigsegg CCR', id: 'list-05' },
{ text: 'McLaren F1', id: 'list-06' },
{ text: 'Aston Martin One- 77', id: 'list-07' },
{ text: 'Jaguar XJ220', id: 'list-08' },
{ text: 'McLaren P1', id: 'list-09' },
{ text: 'Ferrari LaFerrari', id: 'list-10' },
];
return (
// specifies the tag for render the ListBox component
<ListBoxComponent dataSource={data} />
);
}
export default App;
Run the application
Now run the npm run dev
command in the console to start the development server. This command compiles your code and serves the application locally, opening it in the browser.
npm run dev
The following example shows a basic Listbox component.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ListBoxComponent } from '@syncfusion/ej2-react-dropdowns';
function App() {
// define the array of object
let data = [
{ text: 'Hennessey Venom', id: 'list-01' },
{ text: 'Bugatti Chiron', id: 'list-02' },
{ text: 'Bugatti Veyron Super Sport', id: 'list-03' },
{ text: 'SSC Ultimate Aero', id: 'list-04' },
{ text: 'Koenigsegg CCR', id: 'list-05' },
{ text: 'McLaren F1', id: 'list-06' },
{ text: 'Aston Martin One- 77', id: 'list-07' },
{ text: 'Jaguar XJ220', id: 'list-08' },
{ text: 'McLaren P1', id: 'list-09' },
{ text: 'Ferrari LaFerrari', id: 'list-10' },
];
return (
// specifies the tag for render the ListBox component
<ListBoxComponent dataSource={data}/>);
}
export default App;
ReactDOM.render(<App />, document.getElementById('sample'));
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ListBoxComponent } from '@syncfusion/ej2-react-dropdowns';
function App() {
// define the array of object
let data: { [key: string]: Object }[] = [
{ text: 'Hennessey Venom', id: 'list-01' },
{ text: 'Bugatti Chiron', id: 'list-02' },
{ text: 'Bugatti Veyron Super Sport', id: 'list-03' },
{ text: 'SSC Ultimate Aero', id: 'list-04' },
{ text: 'Koenigsegg CCR', id: 'list-05' },
{ text: 'McLaren F1', id: 'list-06' },
{ text: 'Aston Martin One- 77', id: 'list-07' },
{ text: 'Jaguar XJ220', id: 'list-08' },
{ text: 'McLaren P1', id: 'list-09' },
{ text: 'Ferrari LaFerrari', id: 'list-10' },
];
return (
// specifies the tag for render the ListBox component
<ListBoxComponent dataSource={data}/>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById('sample'));