You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
You can also use<NextTopLoader /> inpages router, but it's recommended to use<PagesTopLoader /> foruseRouter hook support fromnextjs-toploader version 2.6.12 onwards
A custom hook for handling progress indicators using NextTopLoader.
Methods
Name
Description
start
Starts the progress bar
done
Completes the progress bar. Can be forced to complete immediately with an optional force parameter
remove
Removes the progress bar element from the DOM
setProgress
Manually sets the progress value (between 0.0 and 1.0)
inc
Increments the progress bar by a specified amount. If no amount is specified, it makes a small automatic increment
trickle
Adds small random increments to the progress bar
isStarted
Checks if the progress bar has been started
isRendered
Checks if the progress bar is rendered in the DOM
getPositioningCSS
Returns the positioning CSS property of the progress bar
Example Usage
'use client';importReactfrom'react';import{useTopLoader}from'nextjs-toploader';constComponent=()=>{constloader=useTopLoader();return(<div><buttontype="button"onClick={()=>loader.start()}> Start</button><buttontype="button"onClick={()=>loader.setProgress(0.5)}> Set Progress</button></div>);};exportdefaultComponent;
Usage with React, Vite React or any other React Based Framework
For rendering add<NextTopLoader /> to yourreturn() inside the component inApp() in your App.js:
importNextTopLoaderfrom'nextjs-toploader';constApp=()=>{return(<div><Router><NextTopLoader/><Routes>{/* Your Routes Here */}</Routes></Router></div>);};exportdefaultApp;
Default Configuration
If no props are passed to<NextTopLoader />, below is the default configuration applied.