Automatic skeleton UI generation for React components
npm install react-auto-skeleton-z
!Downloads
---
Automatic skeleton UI generation for React components.
Plugin-first, component-driven, layout-aware skeletons ā no wrapper required.
---
- Auto-generate skeletons from real components
- Component-driven (Component.skeleton) or plugin-driven
- Layout-aware ā zero layout shift
- Async / lazy component support
- Works with any UI library (Antd / MUI / custom)
- Hook API: useAutoSkeleton
---
``bash`
npm install react-auto-skeleton-zor
yarn add react-auto-skeleton-z
- Import global CSS for animation:
`ts`
import "react-auto-skeleton-z/styles.css"
---
#### 1ļøā£ Basic usage (component .skeleton property)
`tsx
import React from "react"
import ReactDOM from "react-dom"
import { AutoSkeleton, SkeletonCircle, SkeletonText, SkeletonRect } from "react-auto-skeleton-z"
import "react-auto-skeleton-z/styles.css"
// Real component
function UserCard({ user }) {
return (
{user.email}
// Define skeleton directly on component
UserCard.skeleton = () => (
const fakeUser = { avatar: "https://i.pravatar.cc/64", name: "John Doe", email: "john@example.com" }
function App({ loading }) {
return (
)
}
ReactDOM.render(
`
ā
Skeleton appears automatically when loading=true loading=false
ā
Real UI renders when
`ts
// Profile.tsx => Next example
import React from "react"
import { SkeletonCircle, SkeletonText } from "react-auto-skeleton-z"
export default function Profile({ user }) {
return (
// Add skeleton for AutoSkeleton
Profile.skeleton = () => (
// lazy profile
const LazyProfile = lazy(() => import("./Profile"))
`
---
#### 2ļøā£ Plugin system
`ts
import { createSkeletonPlugin, AutoSkeleton } from "react-auto-skeleton-z"
const ProfilePlugin = createSkeletonPlugin({
name: "profile",
rules: [
{
match: (el) => el.type?.name === "Profile",
skeleton: "circle"
}
],
})
- Plugin allows automatic detection without defining
.skeleton for every component. ---
#### 3ļøā£ useAutoSkeleton hook
`ts
import React, { lazy, Suspense } from "react"
import { useAutoSkeleton } from "react-auto-skeleton-z"const LazyProfile = lazy(() => import("./Profile"))
function Page({ loading }) {
const content = useAutoSkeleton(
Loading...
return <>{content}>
}
export default Page
`
- Returns a tree with skeletons automatically injected.
---
#### 4ļøā£ Async / Lazy components
`ts
import React, { lazy, Suspense } from "react"
import { AutoSkeleton } from "react-auto-skeleton-z"
const LazyProfile = lazy(() => import("./Profile"))
- Lazy components automatically show skeleton until loaded.
---
#### 5ļøā£ Custom rules (layout-aware)
`ts
loading
rules={[
{
match: (el) => el.props?.style?.borderRadius === "50%",
skeleton: "circle",
},
{
match: (el) => el.type === "button",
skeleton: "rect",
},
]}
>
``- Rules let you match elements dynamically based on props, type, or other heuristics.
---
- Zero manual wiring
- Layout-aware ā no layout shift
- Component-driven ā easy maintenance
- Plugin-friendly ā reusable rules
- Perfect for dashboards, lists, cards, or heavy-loading UIs
---
MIT