npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@alessiofrittoli/react-top-loader

v1.0.1

Published

Displays a top loader progress while navigating on a different page

Readme

React TopLoader 🏋🏼‍♂️

NPM Latest Version Coverage Status Socket Status NPM Monthly Downloads Dependencies

Displays a top loader progress while navigating on a different page

Table of Contents


Getting started

Run the following command to start using react-top-loader in your projects:

npm i @alessiofrittoli/react-top-loader

or using pnpm

pnpm i @alessiofrittoli/react-top-loader

Overview

Progress updates aren't managed via React state updates but they're based on simple CSS modifications.

This library listen for link clicks, history push and replace states and checks effective navigation in order to start updating navigation progresses.

To avoid negatively impacting your application INP value we use the useDeferCallback exported by @alessiofrittoli/react-hooks library which defers tasks attached to user interactions.


API Reference

React Components

TopLoader

Displays a top loader progress while navigating on a different page.

⚠️ This Component should be mounted once, preferably in the root layout of your application and shouldn't be unmounted when navigating on a different page.

This Component internally use the TopLoaderProvider Component in order to expose the useTopLoaderApi widely in your app.

| Property | Type | Description | | ----------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | Component | React.FC<TopLoaderProgressBarProps> | A React Component which renders a custom progress bar. It must accepts TopLoaderProgressBarProps as props. |

Other properties are inherited by the TopLoaderProviderProps and TopLoaderProgressBarProps.


TopLoaderProgressBar

Simple TopLoader progress bar.

It requires a React.RefObject through the progressBarRef property which will be used to update the progress bar styles based on the current progress value.

This Component is internally used by the TopLoader Component but it is exported for custom implementations.

TopLoaderProgressBarProps

| Property | Type | Description | | ---------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | | progressBarRef | React.RefObject<HTMLDivElement\|null> | The React.RefObject attached to the HTMLDivElement which is then used to update styles based on the current progress value. |

Other properties are inherited by the React.ComponentProps<'div'> type and not documented here.


React Hooks

useTopLoaderApi

TopLoader base API React hook.

It provides status and methods needed to easly handle continuous progress update.

This hook is internally used by TopLoaderProvider Component but it is exported for custom implementations.

Types
UseTopLoaderApiOptions

Defines accepted properties in useTopLoaderApi options.

  • onStart?: OnStartHandler - A custom callback executed when the start method is called.
  • onTick?: OnTickHandler - A custom callback executed when the progress value is updated.
  • onStop?: OnStopHandler - A custom callback executed when the stop method is called.

OnStartHandler

A custom callback executed when the start method is called.

() => void

OnTickHandler

A custom callback executed when the progress value is updated.

( progress: number ) => void

| Parameter | Type | Description | | ---------- | -------- | -------------------------------------------- | | progress | number | The progress value number from 0 to 100. |


OnStopHandler

A custom callback executed when the stop method is called.

() => void

| Parameter | Type | Default | Description | | ----------------- | ------------------------ | ------- | -------------------------------------------------------------- | | options | UseTopLoaderApiOptions | {} | An object defining custom options. | | options.onStart | OnStartHandler | - | A custom callback executed when the start method is called. | | options.onTick | OnTickHandler | - | A custom callback executed when the progress value is updated. | | options.onStop | OnStopHandler | - | A custom callback executed when the stop method is called. |


Type: UseTopLoaderApi

An object defining progress status and methods.

  • playing: React.RefObject<boolean> - A React.RefObject indicating whether the work is currently playing or not.
  • progress: React.RefObject<number> - A React.RefObject indicating the current progress value.
  • start: () => void - Start the TopLoader work.
  • tick: ( amount?: number ) => boolean - Tick TopLoader progress.
  • stop: () => void - Set progress to 100 and stop the TopLoader work.

useTopLoader

Access to the TopLoader React Context API.

Type: UseTopLoaderApi

This hooks returns the useTopLoaderApi result exposed through the TopLoaderContext.


React Context API

TopLoaderContext

The TopLoaderContext creates a React Context that allows useTopLoaderApi exposure.


TopLoaderProvider

The TopLoaderProvider Component exposes the useTopLoaderApi state and functions and handles start, tick and stop of the TopLoader progress while navigating on a different page.

TopLoaderProviderProps

The Component accepts UseTopLoaderApiOptions and children.


Next.js Integration

If you're developing a Next.js web application with the App Router, this library exports some wrappers required for a better integration.

useRouter

Extends the Next.js router with top loader integration.

This hook wraps the Next.js router and triggers a top loader animation whenever a navigation action (push or replace) changes the current pathname. It exposes the standard router methods (back, forward, refresh, prefetch) along with the enhanced push and replace methods.

It's usage remain unchanged so please refer to the official useRouter documention for more information.


Usage examples

Basic usage

Customizing progress bar styles

Progress bar custom component

Navigating with Next.js App Router

Development

Install depenendencies

npm install

or using pnpm

pnpm i

Build the source code

Run the following command to test and build code for distribution.

pnpm build

ESLint

warnings / errors check.

pnpm lint

Jest

Run all the defined test suites by running the following:

# Run tests and watch file changes.
pnpm test:watch

# Run tests in a CI environment.
pnpm test:ci

Run tests with coverage.

An HTTP server is then started to serve coverage files from ./coverage folder.

⚠️ You may see a blank page the first time you run this command. Simply refresh the browser to see the updates.

test:coverage:serve

Contributing

Contributions are truly welcome!

Please refer to the Contributing Doc for more information on how to start contributing to this project.

Help keep this project up to date with GitHub Sponsor.

GitHub Sponsor


Security

If you believe you have found a security vulnerability, we encourage you to responsibly disclose this and NOT open a public issue. We will investigate all legitimate reports. Email [email protected] to disclose any security vulnerabilities.

Made with ☕