Next Top Loader

PreviousNext

A Next.js compatible top loading bar component with automatic navigation detection and customizable progress indicators.

Installation

pnpm dlx shadcn@latest add https://ui.nowts.app/r/next-top-loader.json

Usage

Add the NextTopLoader component to your root layout:

// app/layout.tsx
import { NextTopLoader } from "@/components/ui/next-top-loader"
 
export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>
        <NextTopLoader />
        {children}
      </body>
    </html>
  )
}

The component will automatically show a loading bar at the top of the page during navigation.

Customization

Customize the appearance by passing props:

<NextTopLoader color="#3b82f6" height={3} showSpinner={false} />

Manual Control

You can manually trigger the loading bar:

import { useTopLoader } from "@/components/ui/next-top-loader"
 
export function MyComponent() {
  const { start, done } = useTopLoader()
 
  const handleAction = async () => {
    start()
    await someAsyncAction()
    done()
  }
 
  return <button onClick={handleAction}>Start Action</button>
}

Props

PropTypeDefaultDescription
colorstring"hsl(var(--primary))"Loading bar color
heightnumber2Loading bar height in pixels
showSpinnerbooleanfalseShow spinner on the right