1.0.29 • Published 5 months ago
@fastfollowsoftware/tools v1.0.29
@fastfollowsoftware/tools
npm i @fastfollowsoftware.com/toolsProgress Bar
To install just add the RouteChangeComplete and ProgressBar component to the root of your layout.
import {
ProgressBar,
RouteChangeComplete,
} from '@fastfollowsoftware/tools/router';
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang='en'>
<body>
<RouteChangeComplete />
<ProgressBar />
{children}
</body>
</html>
);
}Router
Trigger Router Events
You can trigger route start / complete events.
This is useful in scenarios where you want to trigger progress bar updates for server actions.
import {
emitActionComplete,
emitActionStart,
} from '@fastfollowsoftware/tools/router';
export const doAction = async (action: Promise<any>) => {
emitActionStart();
const actionResult = await action;
emitActionComplete();
return actionResult;
};Listen to Router Events
You can subscribe to router events using the on method.
Here's an example where we listen to router events and post messages to the parent.
'use client';
import { RouterEvent, on } from '@fastfollowsoftware/tools/router';
import { useEffect } from 'react';
export const MyComponent = () => {
useEffect(() => {
const handleRouteChangeStart = () => {
// handle route change start event
};
const handleRouteChangeComplete = () => {
// handle route change complete event
};
on(RouterEvent.RouteChangeStart, handleRouteChangeStart);
on(RouterEvent.RouteChangeComplete, handleRouteChangeComplete);
// deregister on unmount
return () => {
on(RouterEvent.RouteChangeStart, handleRouteChangeStart);
on(RouterEvent.RouteChangeComplete, handleRouteChangeComplete);
};
}, []);
return <></>;
};1.0.29
5 months ago
1.0.28
8 months ago
1.0.27
1 year ago
1.0.26
1 year ago
1.0.25
1 year ago
1.0.24
2 years ago
1.0.23
2 years ago
1.0.19
2 years ago
1.0.18
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.22
2 years ago
1.0.21
2 years ago
1.0.20
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.12
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago