typescriptbeginner
Skeleton Loader Component
Animated skeleton placeholder component with configurable shapes for loading states.
typescriptPress ⌘/Ctrl + Shift + C to copy
interface SkeletonProps {
width?: string | number;
height?: string | number;
variant?: 'text' | 'circle' | 'rect';
className?: string;
}
export function Skeleton({ width = '100%', height = 20, variant = 'text', className = '' }: SkeletonProps) {
const baseClass = 'animate-pulse bg-gray-700';
const variantClass = {
text: 'rounded',
circle: 'rounded-full',
rect: 'rounded-lg',
}[variant];
return (
<div
className={`${baseClass} ${variantClass} ${className}`}
style={{ width, height }}
role="status"
aria-label="Loading"
/>
);
}
export function SkeletonCard() {
return (
<div className="space-y-3 p-4">
<Skeleton variant="rect" height={200} />
<Skeleton width="60%" />
<Skeleton width="80%" />
<Skeleton width="40%" />
</div>
);
}Use Cases
- Content loading states
- Page transitions
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
typescriptbeginner
Loading UI with Skeleton Screens
Create loading.tsx skeleton screens for instant navigation feedback with Next.js App Router.
Best for: Route transition loading states
#nextjs#loading
typescriptintermediate
Toast Notification System
Build a toast notification system with auto-dismiss, stacking, animations, and severity levels.
Best for: User feedback notifications
#react#toast
typescriptbeginner
Search with Text Highlighting
Build a search component that highlights matching text within results using safe HTML rendering.
Best for: Search results display
#react#search
typescriptintermediate
Streaming with Loading UI and Suspense
Use loading.tsx and React Suspense to stream UI progressively in Next.js App Router.
Best for: dashboards
#nextjs#streaming