Getting Started
8 May 20256 minutes to read
This section briefly explains how to create a simple SplitButton component and configure its available functionalities in React.
Dependencies
The following list of dependencies are required to use the SplitButton
component in your application.
|-- @syncfusion/ej2-react-splitbuttons
|-- @syncfusion/ej2-react-base
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-splitbuttons
|-- @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 SplitButton component, use the following command
npm install @syncfusion/ej2-react-splitbuttons –save
Adding CSS reference
Import the SplitButton component required CSS references as follows in src/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";
Adding SplitButton component
Now, you can start adding SplitButton component in the application. For getting started, add the SplitButton component in src/App.tsx
file using following code.
Add the below code in the src/App.tsx
to initialize the SplitButton.
import { enableRipple } from '@syncfusion/ej2-base';
import { SplitButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import './App.css';
enableRipple(true);
// To render SplitButton.
function App() {
return (
<div style=>
<SplitButtonComponent id="element"/>
</div>
);
}
export default App;
Binding data source
After initialization, populate the SplitButton with data using the items
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 * as React from 'react';
import './App.css';
enableRipple(true);
// To render SplitButton.
function App() {
let items: ItemModel[] = [
{
text: 'Cut',
},
{
text: 'Copy',
},
{
text: 'Paste',
}];
return (
<div style=><SplitButtonComponent id="element" items = {items}> Paste
</SplitButtonComponent>
</div>
);
}
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 SplitButton component.
import { enableRipple } from '@syncfusion/ej2-base';
import { SplitButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
// To render SplitButton.
function App() {
let items = [
{
text: 'Cut',
},
{
text: 'Copy',
},
{
text: 'Paste',
}
];
return (<div>
<SplitButtonComponent id="element" items={items}> Paste </SplitButtonComponent>
</div>);
}
export default App;
ReactDom.render(<App />, document.getElementById('button'));
import { enableRipple } from '@syncfusion/ej2-base';
import { ItemModel, SplitButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
// To render SplitButton.
function App() {
let items: ItemModel[] = [
{
text: 'Cut',
},
{
text: 'Copy',
},
{
text: 'Paste',
}];
return (
<div>
<SplitButtonComponent id="element" items = {items}> Paste </SplitButtonComponent>
</div>
);
}
export default App;
ReactDom.render(<App />,document.getElementById('button'));