How to add Skeleton Loading in NextJS ?
Last Updated : 26 Jul, 2024
Skeleton Loading in Next.js provides a placeholder UI while content is loading, improving perceived performance and user experience. It visually represents loading elements, ensuring a smoother, more engaging application.
Approach
To add skeleton loading in nextjs application we are going to use the react-loading-skeleton npm package. The react-loading-skeleton package helps us to add a skeleton loading anywhere in our app. So first, we will install the react-loading-skeleton package and then we will add a loading screen on our homepage.
Steps to Create NextJS Application
Step 1: Initialize the Nextjs App
Initialize the nextjs project using the below command and move to the project directory:
npx create-next-app gfg
cd gfg
Step 2: Install the required package:
Now we will install the react-loading-skeleton NPM package using the below command:
npm i react-loading-skeleton
Project Structure:

The updated dependencies in the package.json file will be:
"dependencies": {
"next": "14.2.4",
"react": "^18",
"react-dom": "^18",
"react-loading-skeleton": "^3.4.0"
},
Example: This example demonstrates skelton loading with the help of npm package react-loading-skeleton along with the conditional rendering.
JavaScript // Filename - pages/index.js import React, { useState } from 'react' import Skeleton from 'react-loading-skeleton' import 'react-loading-skeleton/dist/skeleton.css' export default function SkeletonLoading() { const [checked, setChecked] = React.useState(false) const handleChange = () => { setChecked(!checked) } return ( <div> <label> <input type='checkbox' checked={checked} onChange={handleChange} /> Loading </label> <div> {checked ? ( <Skeleton /> ) : ( <p>NextJs Skeleton Loading - GeeksforGeeks</p> )} </div> </div> ) }
Explanation: In the above example first, we are importing our Skeleton component from the installed package. After that, we are using the Skeleton component inside a new function. We are also using react hook to check the current value in the checkbox. If the checkbox is checked then we are showing our loading screen.
Steps to run the application: Run the below command in the terminal to run the app.
npm run dev
Output:
Similar Reads
How to add Loading Quotes in Next.js ? In this article, we are going to learn how we can add loading quotes in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components condi
2 min read
How to Add Spinner Loader in Next.js ? In web applications, providing a smooth and responsive user experience is very important. One way to achieve this is by adding a spinner loader to indicate that a process is ongoing, such as fetching data or loading a new page. In this article, we'll explore how to add a spinner loader in a Next.js
2 min read
How to Add Stylesheet in Next.js ? In Next.js, adding a stylesheet enhances your app's styling capabilities. Import CSS files directly in your components or pages using ES6 import syntax. Next.js optimizes and includes these styles in the build process, ensuring efficient and modular CSS management.In this post, we are going to learn
4 min read
How To Add Styling To An Active Link In NextJS? Styling active links is important for enhancing user navigation by providing visual feedback on the current page or section. In Next.js, you can achieve this by using the Link component from next/link and applying styles conditionally based on the active route. In this article, we will learn about h
3 min read
How To Add Navbar To All Pages In NextJS ? A navbar is a common UI element used to navigate between different sections or pages of a website. Adding a navbar to all pages ensures consistent navigation across the site. This article will explore how we can add a navbar to all pages In NextJS. Output Preview: Prerequisites:NextJSReactJSReact Ho
3 min read