1.0.24 • Published 2 months ago

@fastfollowsoftware/tools v1.0.24

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

@fastfollowsoftware/tools

npm i @fastfollowsoftware.com/tools

Progress 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.24

2 months ago

1.0.23

2 months ago

1.0.19

3 months ago

1.0.18

3 months ago

1.0.17

3 months ago

1.0.16

3 months ago

1.0.22

3 months ago

1.0.21

3 months ago

1.0.20

3 months ago

1.0.15

3 months ago

1.0.14

3 months ago

1.0.13

3 months ago

1.0.12

3 months ago

1.0.9

3 months ago

1.0.8

3 months ago

1.0.11

3 months ago

1.0.10

3 months ago

1.0.7

3 months ago

1.0.6

3 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago