Getting Started with React Spinner component
22 Jul 20266 minutes to read
This section explains the steps required to create a simple React Spinner component and demonstrate its basic usage in a React environment.
Ready to streamline your Syncfusion® React development? Discover the full potential of Syncfusion® React components with Syncfusion® AI Coding Assistant. Effortlessly integrate, configure, and enhance your projects with intelligent, context-aware code suggestions, streamlined setups, and real-time insights—all seamlessly integrated into your preferred AI-powered IDEs like VS Code, Cursor, Syncfusion® CodeStudio and more. Explore Syncfusion® AI Coding Assistant.
Prerequisites
System requirements for Syncfusion® React UI components
Prerequisites
System requirements for Syncfusion® React UI components
Set up the Vite project
To create a new Vite project, use one of the commands that are specific to either NPM or Yarn.
npm create vite@latest my-project -- --template reactyarn create vite my-project --template reactAfter running the command, you will be prompted with a series of interactive questions to configure your project. Select the appropriate options for each prompt:
-
Select a linter to use: Choose the linter for your project (for example,
ESLint). -
Install with npm and start now?: Type
Yesto proceed with installing the dependencies and automatically start the development server, orNoto install dependencies manually later.
Navigate into the project directory with:
cd my-project
Add Syncfusion® React packages
Syncfusion® React component packages are available at npmjs.com. To use Syncfusion® React components in the project, install the corresponding npm package.
To install the React component package, use the following command:
npm install @syncfusion/ej2-react-dropdownsyarn add @syncfusion/ej2-react-dropdownsImport Syncfusion® CSS styles
Themes for Syncfusion® React components can be applied using CSS or SASS files from the npm theme packages, CDN, CRG, or Theme Studio. For more information, see the themes documentation.
This guide uses the Tailwind 3 theme as an example, sourced from the theme package. In this package, each component includes an index.css file that automatically loads all the required dependency styles. To install the Tailwind 3 theme package, use the following command:
npm install @syncfusion/ej2-tailwind3-themeyarn add @syncfusion/ej2-tailwind3-themeBy default, Vite projects include a src/index.css file with default styles. These default styles may conflict with Syncfusion component styles. Clear all content from the src/index.css file to prevent style conflicts.
The required styles for the Spinner component are imported in the src/App.css file:
@import "@syncfusion/ej2-tailwind3-theme/styles/spinner/index.css";You can also refer to the combined CSS file for all Syncfusion components in your application. For more information, see the documentation on referring themes through npm packages.
Adding Spinner component
The React Spinner component can be added to the application by following these steps. To get started, add the Spinner component to the src/App.jsx file using the following code.
import { createSpinner, showSpinner } from '@syncfusion/ej2-popups';
import { useEffect } from "react";
import './App.css';
function App() {
useEffect(() => {
componentDidMount();
}, []);
function componentDidMount() {
//createSpinner() method is used to create spinner
createSpinner({
// Specify the target for the spinner to show
target: document.getElementById('container') as HTMLElement,
});
// showSpinner() will make the spinner visible
showSpinner(document.getElementById('container') as HTMLElement);
}
return (<div className="control-pane">
<div id="container" className="control-section col-lg-12 spinner-target"></div>
</div>);
}
export default App;Run the application
Run the npm run dev command in the terminal to start the development server. This command compiles your code and serves the application locally, opening it in the browser.
npm run devThe output appears as follows in the preview sample.
[Functional-component]
import { createSpinner, showSpinner } from '@syncfusion/ej2-popups';
import { useEffect } from "react";
function App() {
useEffect(() => {
componentDidMount();
}, []);
function componentDidMount() {
//createSpinner() method is used to create spinner
createSpinner({
// Specify the target for the spinner to show
target: document.getElementById('container'),
});
// showSpinner() will make the spinner visible
showSpinner(document.getElementById('container'));
}
return (<div className="control-pane">
<div id="container" className="control-section col-lg-12 spinner-target"></div>
</div>);
}
export default App;import { createSpinner, showSpinner } from '@syncfusion/ej2-popups';
import { useEffect } from "react";
function App() {
useEffect(() => {
//createSpinner() method is used to create spinner
createSpinner({
// Specify the target for the spinner to show
target: document.getElementById('container') as HTMLElement,
});
// showSpinner() will make the spinner visible
showSpinner(document.getElementById('container') as HTMLElement);
}, []);
return (
<div className="control-pane">
<div id="container"
className="control-section col-lg-12 spinner-target"
></div>
</div>
);
}
export default App;