Getting Started
7 Nov 20233 minutes to read
This section explains how to create a simple React Carousel, and configure its available functionalities in React.
To get started quickly with React Carousel component, you can check out this video:
Dependencies
The following list of dependencies are required to use the Carousel component in your application.
|-- @syncfusion/ej2-react-navigations
|-- @syncfusion/ej2-react-base
|-- @syncfusion/ej2-navigations
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-buttons
Setup your development environment
To set-up a React application, choose any of the following ways. The best and easiest way is to use the create-react-app. It sets up your development environment in JavaScript and improvise your application for production. Refer to the installation instructions of create-react-app
.
npx create-react-app my-app
cd my-app
npm start
or
yarn create react-app my-app
cd my-app
yarn start
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
Besides using the npm package runner tool, also create an application from the npm init
. To begin with the npm init
, upgrade the npm
version to npm 6+
.
npm init react-app my-app
cd my-app
npm start
Adding Syncfusion packages
All the available Essential JS 2 packages are published in npmjs.com
public registry.
To install Carousel
component, use the following command
npm install @syncfusion/ej2-react-navigations --save
The above command installs Carousel dependencies
which are required to render the component in the React
environment.
Adding Style sheet to the Application
Add Carousel component’s styles as given below in App.css
.
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
Add Carousel to the project
Now, you can create Carousel
component in the application. Add Carousel
component in src/App.ts
file using the following code snippet.
import { CarouselComponent, CarouselItemsDirective, CarouselItemDirective } from "@syncfusion/ej2-react-navigations";
import * as React from "react";
const App = () => {
return (<div className='control-container'>
<CarouselComponent>
<CarouselItemsDirective>
<CarouselItemDirective template='<figure class="img-container"><img src="https://ej2.syncfusion.com/products/images/carousel/cardinal.png" alt="cardinal" style="height:100%;width:100%;" /><figcaption class="img-caption">Cardinal</figcaption></figure>'/>
<CarouselItemDirective template='<figure class="img-container"><img src="https://ej2.syncfusion.com/products/images/carousel/hunei.png" alt="kingfisher" style="height:100%;width:100%;" /><figcaption class="img-caption">Kingfisher</figcaption></figure>'/>
<CarouselItemDirective template='<figure class="img-container"><img src="https://ej2.syncfusion.com/products/images/carousel/costa-rica.png" alt="keel-billed-toucan" style="height:100%;width:100%;" /><figcaption class="img-caption">Keel-billed-toucan</figcaption></figure>'/>
<CarouselItemDirective template='<figure class="img-container"><img src="https://ej2.syncfusion.com/products/images/carousel/kaohsiung.png" alt="yellow-warbler" style="height:100%;width:100%;" /><figcaption class="img-caption">Yellow-warbler</figcaption></figure>'/>
<CarouselItemDirective template='<figure class="img-container"><img src="https://ej2.syncfusion.com/products/images/carousel/bee-eater.png" alt="bee-eater" style="height:100%;width:100%;" /><figcaption class="img-caption">Bee-eater</figcaption></figure>'/>
</CarouselItemsDirective>
</CarouselComponent>
</div>);
}
export default App;
Run the application
Run the application in the browser using the following command:
npm start
NOTE
You can also explore our React Carousel example that shows you how to configure the Carousel in React.