Loading UI
Learn how to create custom loading states with loading.tsx for a better user experience.
Bini.js provides a built-in loading spinner, but you can create custom loading.tsx files to show your own loading UI while page content loads.
How it Works
The loading.tsx file automatically wraps the page in a Suspense boundary. The loading UI is shown immediately on navigation while the page content streams in.
- User clicks a link or navigates to a route
- Loading UI appears instantly
- Page content loads in the background
- Once ready, the loading UI is replaced with the actual page
Global Loading UI
Create a loading.tsx file in the root of your app directory to show a loading state for all routes.
Nested Loading UI
You can create route-specific loading states by placing loading.tsx in subdirectories. The closest loading file to the page being navigated to will be used.
| Navigation | Loading UI Used |
|---|---|
| / → /about | app/loading.tsx |
| / → /blog | app/blog/loading.tsx |
| / → /blog/hello-world | app/blog/[slug]/loading.tsx |
| / → /dashboard | app/dashboard/loading.tsx |
Skeleton Examples
Skeletons provide a better user experience than spinners by showing the approximate layout of the content.
Blog Post Skeleton
Dashboard Skeleton
Card Grid Skeleton
Loading with Layout
Loading UI is shown inside the layout hierarchy. Layouts remain visible and interactive while the page loads.
This means headers, sidebars, and navigation remain usable while the main content loads.
Custom Spinners
Create branded spinners that match your design system:
Built-in Fallback
If you don't create a loading.tsx file, Bini.js uses a built-in spinner:
- Dark mode aware — adapts to your theme
- Centered on the screen
- Clean, minimal design
- Automatically used when no custom loading UI exists
The built-in spinner is a good starting point, but creating custom loading UI is recommended for production applications.
Best Practices
- •Use skeletons for content-heavy pages — They provide better UX than spinners.
- •Create nested loading states — Different sections can have different loading UIs.
- •Keep loading UI lightweight — Fast to render and minimal DOM impact.
- •Use animations sparingly — Too much animation can be distracting.
- •Match your brand — Use your brand colors and design language.