--- title: Getting Started description: 'Get started with the KendoReact ListBox package and learn how to use the ListBox component in React projects.' components: ['listbox'] slug: get_started_listbox position: 10 --- # Getting Started with the KendoReact ListBox This guide provides essential information about using the KendoReact ListBox package—you will learn how to install the ListBox package and add a free React ListBox component to your project.
After completing this guide, you will have a free React [ListBox](slug://overview_listbox) up and running. {% meta height:610 %} {% embed_file get-started/func/app.tsx preview %} {% embed_file get-started/func/main.tsx %} {% endmeta %} ## Before You Begin To follow the steps in this guide, you need to have a React project set up. If you don't have one, you can create a new React application using Vite by running the following command in your terminal: ```sh npm create vite@latest my-app -- --template react ``` This guide requires that you have **basic knowledge of React and TypeScript**, and that you have already created [**a blank React project**](slug://getting_started). > tip You can speed up the development of your KendoReact application with the [Kendo UI Template Wizard for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=KendoUI.kendotemplatewizard). ## Install the Component To install the ListBox package, run the following command in the root folder of your React project: ```sh npm i @progress/kendo-react-listbox ``` Run these commands in the root of your React project to install the KendoReact ListBox package and its [dependencies](#kendoreact-listbox-dependencies), and the Kendo UI [Default theme](https://www.telerik.com/kendo-react-ui/components/styling/theme-default/). ## Import the Component Place the `import` statements in the App component file (for example: `src/App.tsx`) for your project. ```tsx import { ListBox, ListBoxToolbar, processListBoxData, ListBoxToolbarClickEvent, ListBoxItemClickEvent } from '@progress/kendo-react-listbox'; ``` ## Use the Component 1. Import the data for the ListBox. ```tsx import { data } from './data'; ``` 1. Create a state variable to hold the data for the two ListBox components. ```tsx const [state, setState] = React.useState({ employees: data, developers: [] }); ``` 1. Set the [selectedField]({% slug api_listbox_listboxprops %}#toc-selectedfield) value. That value will determine which items are selected. ```tsx const SELECTED_FIELD = 'selected'; ``` 1. Handle the [onItemClick]({% slug api_listbox_listboxprops %}#toc-onitemclick) event of the ListBox to select or deselect items. ```tsx const handleItemClick = (event, data, connectedData) => { setState({ ...state, [data]: state[data].map((item) => { if (item.name === event.dataItem.name) { item[SELECTED_FIELD] = !item[SELECTED_FIELD]; } else if (!event.nativeEvent.ctrlKey) { item[SELECTED_FIELD] = false; } return item; }), [connectedData]: state[connectedData].map((item) => { item[SELECTED_FIELD] = false; return item; }) }); }; ``` 1. Handle the [onToolClick]({% slug api_listbox_listboxtoolbarprops %}#toc-ontoolclick) event of the ListBoxToolbar to update the lists. ```tsx const handleToolBarClick = (e: ListBoxToolbarClickEvent) => { let toolName: string = e.toolName || ''; let result: any = processListBoxData(state.employees, state.developers, toolName, SELECTED_FIELD); setState({ ...state, employees: result.listBoxOneData, developers: result.listBoxTwoData }); }; ``` 1. Add the markup of the two components to the `src/App.js` file in your project. ```tsx return (