Loading state
Also called loading UI or loading indicator
The view a screen shows while its data is on the way, designed together with the outcomes that follow: loaded, empty, or error.
type Message = { id: string; from: string; preview: string };
// Wire these to your data hook, such as React Query's useQuery.
type Props = {
status: 'pending' | 'error' | 'success';
messages?: Message[];
onRetry: () => void;
};
export function MessagesCard({ status, messages = [], onRetry }: Props) {
return (
// A fixed height keeps the card from jumping between states.
<section
aria-busy={status === 'pending'}
className='grid h-56 w-80 rounded-2xl border p-4 text-sm'
>
{status === 'pending' && (
// Fades in after 200ms, so fast responses never flash a skeleton.
<div className='space-y-4 transition-opacity delay-200 starting:opacity-0'>
{[0, 1, 2].map((row) => (
<div key={row} className='flex gap-3 motion-safe:animate-pulse'>
<div className='size-10 rounded-full bg-muted' />
<div className='h-10 flex-1 rounded-lg bg-muted' />
</div>
))}
</div>
)}
{status === 'error' && (
<div className='place-self-center text-center'>
<p>Couldn't load messages.</p>
<button
type='button'
onClick={onRetry}
className='mt-3 rounded-lg border px-3 py-1.5 font-medium hover:bg-muted'
>
Try again
</button>
</div>
)}
{status === 'success' && messages.length === 0 && (
<div className='place-self-center text-center'>
<p className='font-medium'>No messages yet</p>
<p className='text-muted-foreground'>
New conversations show up here.
</p>
</div>
)}
{status === 'success' && messages.length > 0 && (
<ul className='space-y-3'>
{messages.map((message) => (
<li key={message.id} className='truncate'>
<span className='font-medium'>{message.from}</span>{' '}
{message.preview}
</li>
))}
</ul>
)}
</section>
);
}Give the messages list four states: a skeleton of three gray rows (an avatar circle and two text lines) with a gentle pulse while loading, the loaded list, an empty state that says "No messages yet" with a short hint, and an error state with a "Try again" button that refetches. Keep the card the same height in every state, delay the skeleton by 200ms so fast loads don’t flash, and turn off the pulse when prefers-reduced-motion is set.
Paste into Layerwise or any AI coding tool.
What is Loading state?
Any screen that fetches data passes through a loading state before it shows anything useful. Common choices are a skeleton screen (gray shapes in the layout of the coming content), a spinner, or a progress bar. It is often the first thing people see, so it shapes how fast the app feels.
Plan it together with the three outcomes that can follow: loaded with data, empty (the request worked but there is nothing yet), and error (the request failed). Each needs its own design. An empty inbox should say so and suggest a next step, and an error should explain what happened and offer a Try again button.
Show a skeleton when you know the shape of the content, and a spinner for short actions like saving. Wait 200–300ms before showing any indicator so fast responses don’t flash, and keep the container the same size across states so the page doesn’t jump. Mark the region with aria-busy="true" while it loads so screen readers know to wait.
Often confused with
- Skeleton screen
- A skeleton screen is one way to show a loading state: gray placeholder shapes in the layout of the content that is coming.
Related terms
All termsSkeleton screen
A loading placeholder made of gray blocks shaped like the content on its way, often with a soft shimmer, that the real content replaces.
Spinner
A small looping animation, usually a rotating ring, that shows the app is busy with a short task of unknown length.
Empty state
What a screen shows when there is nothing in it yet: a short message, often a simple illustration, and one clear action to add the first item.
Perceived performance
How fast an app feels to people, which skeleton screens, instant feedback, and progressive loading can improve even when the real wait stays the same.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.