11 Aug 20256 minutes to read
This section briefly explains how to create a simpleSplitButton component and configure its available functionalities in React.
The following list of dependencies are required to use theSplitButton
component in your application.
|--@syncfusion/ej2-react-splitbuttons|--@syncfusion/ej2-react-base|--@syncfusion/ej2-base|--@syncfusion/ej2-splitbuttons|--@syncfusion/ej2-popups|--@syncfusion/ej2-buttons
To easily set up a React application, usecreate-vite-app
, which provides a faster development environment, smaller bundle sizes, and optimized builds compared to traditional tools likecreate-react-app
. For detailed steps, refer to the Viteinstallation 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 thisdocumentation 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-tscd my-appnpm run dev
To set-up a React application in JavaScript environment, run the following command.
npm create vite@latest my-app -- --template reactcd my-appnpm run dev
All the available Essential® JS 2 packages are published innpmjs.com
public registry. You can choose the component that you want to install.
To install SplitButton component, use the following command
npm install @syncfusion/ej2-react-splitbuttons –save
Import the SplitButton component required CSS references as follows insrc/App.css
.
/* import the SplitButton dependency styles */@import"../node_modules/@syncfusion/ej2-base/styles/material.css";@import"../node_modules/@syncfusion/ej2-buttons/styles/material.css";@import"../node_modules/@syncfusion/ej2-popups/styles/material.css";@import"../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
Now, you can start adding SplitButton component in the application. For getting started, add the SplitButton component insrc/App.tsx
file using following code.
Add the below code in thesrc/App.tsx
to initialize the SplitButton.
import{enableRipple}from'@syncfusion/ej2-base';import{SplitButtonComponent}from'@syncfusion/ej2-react-splitbuttons';import*asReactfrom'react';import'./App.css';enableRipple(true);// To render SplitButton.functionApp(){return(<divstyle={{marginTop:'150px'}}><SplitButtonComponentid="element"/></div>);}exportdefaultApp;
After initialization, populate the SplitButton with data using theitems
property. Here, an array of string values is passed to the SplitButton component.
import{enableRipple}from'@syncfusion/ej2-base';import{ItemModel,SplitButtonComponent}from'@syncfusion/ej2-react-splitbuttons';import*asReactfrom'react';import'./App.css';enableRipple(true);// To render SplitButton.functionApp(){letitems:ItemModel[]=[{text:'Cut',},{text:'Copy',},{text:'Paste',}];return(<divstyle={{marginTop:'150px'}}><SplitButtonComponentid="element"items={items}>Paste</SplitButtonComponent></div>);}exportdefaultApp;
Now run thenpm 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 SplitButton component.
import{enableRipple}from'@syncfusion/ej2-base';import{SplitButtonComponent}from'@syncfusion/ej2-react-splitbuttons';import*asReactfrom'react';import*asReactDomfrom'react-dom';enableRipple(true);// To render SplitButton.functionApp(){letitems=[{text:'Cut',},{text:'Copy',},{text:'Paste',}];return(<div><SplitButtonComponentid="element"items={items}>Paste</SplitButtonComponent></div>);}exportdefaultApp;ReactDom.render(<App/>,document.getElementById('button'));
import{enableRipple}from'@syncfusion/ej2-base';import{ItemModel,SplitButtonComponent}from'@syncfusion/ej2-react-splitbuttons';import*asReactfrom'react';import*asReactDomfrom'react-dom';enableRipple(true);// To render SplitButton.functionApp(){letitems:ItemModel[]=[{text:'Cut',},{text:'Copy',},{text:'Paste',}];return(<div><SplitButtonComponentid="element"items={items}>Paste</SplitButtonComponent></div>);}exportdefaultApp;ReactDom.render(<App/>,document.getElementById('button'));