Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
react-transition-progress
Advanced tools
Readme
Show a progress bar while a React transition is in progress.
npm install react-transition-progress framer-motion
The main package react-transition-progress
exports three APIs: ProgressBarProvider
, ProgressBar
, and useProgress
.
ProgressBarProvider
provides the state and context for ProgressBar
and useProgress
ProgressBar
is the displayed progressbaruseProgress
is the way you start/finish the progressbarThere is also Next.js specific helper for next/link
in react-transition-progress/next
:
Link
is a wrapper for next/link
that is instrumented to show the ProgressBar
For example integrating into the Next.js App Router:
// app/layout.tsx
import { ProgressBar, ProgressBarProvider } from "react-transition-progress";
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>
<ProgressBarProvider>
{/* I.e. using Tailwind CSS to show the progress bar with custom styling */}
<ProgressBar className="fixed h-1 shadow-lg shadow-sky-500/20 bg-sky-500 top-0" />
{children}
</ProgressBarProvider>
</body>
</html>
);
}
Using useProgress
to show the ProgressBar
when the React transition runs:
// components/my-component.tsx
"use client";
import { useState } from "react";
import { useProgress } from "react-transition-progress";
export default function MyComponent() {
const startProgress = useProgress();
const [count, setCount] = useState(0);
return (
<>
<h1>Current count: {count}</h1>
<button
onClick={() => {
startTransition(async () => {
startProgress();
// Introduces artificial slowdown
await new Promise((resolve) => setTimeout(resolve, 2000));
setCount((count) => count + 1);
});
}}
>
Trigger transition
</button>
</>
);
}
Using Next.js helper for Link
to show the progress bar for next/link
:
// app/page.tsx
import { Link } from "react-transition-progress/next";
export default function Home() {
return (
<div>
<h1>Home</h1>
<Link href="/about">Go to about page</Link>
</div>
);
}
See the Contributing Guide.
FAQs
Show a progress bar while a React transition is in progress.
The npm package react-transition-progress receives a total of 197 weekly downloads. As such, react-transition-progress popularity was classified as not popular.
We found that react-transition-progress demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.