DEV Community

Cover image for ๐Ÿฆด Create Smooth Skeleton Loaders in React with `skeleton-loader-ap`
Er. Ankit Parashar
Er. Ankit Parashar

Posted on

๐Ÿฆด Create Smooth Skeleton Loaders in React with `skeleton-loader-ap`

Skeleton loaders are one of the most effective ways to improve perceived performance in a React app. Instead of showing a blank screen or a generic spinner, you simulate the layout of your content while it's loading.

With skeleton-loader-ap, adding responsive, customizable loading placeholders is super simple.

๐Ÿ“ฆ skeleton-loader-ap


โœ… Why Use Skeleton Loaders?

  • ๐Ÿงฉ They hint at content layout before it's loaded
  • ๐Ÿš€ Improve perceived speed and UX
  • ๐Ÿง  More context than loading spinners
  • ๐Ÿ“ฑ Great for images, avatars, text, cards, and more

๐Ÿ“ฆ Installation

Install with npm:


bash
npm install skeleton-loader-ap
Or with Yarn:

bash
Copy
Edit
yarn add skeleton-loader-ap

๐Ÿ”ง Components Overview

1. <Skeleton /> โ€“ Base Skeleton Block

<Skeleton width="100%" height="1rem" borderRadius="6px" />
Props:

width (string | number)

height (string | number)

circle (boolean)

borderRadius (string | number)

placeholder (boolean | string) โ€“ true or custom image path

opacity (number | string)

2. <SkeletonImage /> โ€“ Image Loader


<SkeletonImage size={80} circle placeholder />
Extra Props:

size โ€“ square size for both width/height

circle โ€“ inferred if size is passed

3. <SkeletonParagraph /> โ€“ Multi-line Loader
<SkeletonParagraph
  rows={3}
  widths={['90%', '100%', '80%']}
  spacing="0.75rem"
  placeholder
/>
Props:

rows โ€“ number of lines (default 3)

widths โ€“ array of individual line widths

lineHeight โ€“ default '1rem'

spacing โ€“ default '0.5rem'

placeholder, opacity, borderRadius

4. <SkeletonClientWrapper /> โ€“ Auto Loader Wrapper
<SkeletonClientWrapper
  type="Image"
  size={100}
  circle
  placeholder
  loadertime={3000}
/>


<SkeletonClientWrapper
  type="Paragraph"
  rows={4}
  widths={['90%', '100%', '80%', '70%']}
  placeholder
/>
Props:

type: 'Image' or 'Paragraph'

loadertime: how long (in ms) to show skeleton

All props passed to respective component

๐Ÿช„ useSkeleton Hook
Manually control loading:

const loading = useSkeleton(3000); // `true` for 3 seconds
Use this to conditionally show skeletons or actual content.

๐Ÿ–ผ Placeholder Images
Built-in default image:


<Skeleton placeholder />
Custom image from /public/Images/your-loader.gif:

<Skeleton placeholder="/Images/custom-spinner.gif" />

๐Ÿงช Full Example

import {
  SkeletonClientWrapper,
  SkeletonImage,
  SkeletonParagraph,
} from 'skeleton-loader-ap';

function ProfileLoader() {
  return (
    <div className="flex gap-4">
      <SkeletonClientWrapper
        type="Image"
        size={80}
        circle
        placeholder
        loadertime={3000}
      />
      <SkeletonClientWrapper
        type="Paragraph"
        rows={3}
        widths={['80%', '90%', '70%']}
        placeholder
        spacing="1rem"
      />
    </div>
  );
}
๐ŸŒŸ Features Recap
๐Ÿ›  Highly customizable

๐Ÿงฉ Modular components (Image, Text, Block)

โณ Client-side wrapper for simulated loading

๐Ÿช„ Hook for manual control

๐Ÿ–ผ Built-in + custom image placeholders

๐Ÿ“ฆ Lightweight with no external dependencies

๐Ÿ”— Links(https://github.com/ankitparashar700/npm-skeleton-loader-ap/)
๐Ÿ”— View on NPM

๐Ÿ”ง GitHub Repository

If this helped you, give the package a โญ on GitHub and share it with your dev team!

Happy loading! ๐Ÿฆด
Enter fullscreen mode Exit fullscreen mode

Top comments (0)