A Skeleton Component is used whenever the data is not loaded, the placeholder preview is to be shown to the user. This component displays a placeholder preview of our content. Material UI for React has this component available for us, and it is very easy to integrate. We can use the following approach in ReactJS to use Skeleton Component.
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
Step 3: After creating the ReactJS application, Install the material-ui module using the following command:
npm install @mui/material
Project Structure: It will look like the following.
Project Structure
Example 1: In this example, we will create a Skeleton component for a text, rectangular and circular variants. Please update App.js like below.
Filename: App.js
Javascript
import { Skeleton } from "@mui/material" ; import React from "react" ;   export default function App() {     return (         <div style={{             display: "block" ,             padding: 30         }}>             <h4>                 How to use Skeleton Component in ReactJS?             </h4>             TEXT VARIANT: <Skeleton variant= "text" width={200} />             <br />             RECTANGULAR VARIANT: <Skeleton                 variant= "rect"                 width={110}                 height={220}             />{ " " }             <br />             CIRCLE VARIANT:             <Skeleton variant= "circle"                 width={50} height={50} />{ " " }             <br />         </div>     ); } |
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Example 2: In this example, we will create Skeleton components having different animations. Please update App.js like the below.
Filename: App.js
Javascript
import { Skeleton } from "@mui/material" ; import React from "react" ;   export default function App() {     return (         <div style={{ display: "block" , padding: 30 }}>             <h4>                 How to use Skeleton                 Component in ReactJS?             </h4>             Default animantion: <Skeleton />             Wave animantion: <Skeleton animation= "wave" />             No animantion: <Skeleton animation={ false } />         </div>     ); } |
Steps to run the application:
npm start
Output:
Â
Reference: https://mui.com/material-ui/react-skeleton/#main-content