atlp-rwanda/hackers-ec-Fe

View on GitHub
src/utils/NProgressBar.tsx

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import React, { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

const NProgressBar = ({ children }: { children: React.ReactNode }) => {
    const location = useLocation();

    useEffect(() => {
        const handleStart = () => {
            NProgress.start();
        };

        const handleStop = () => {
            NProgress.done();
        };

        handleStart();
        handleStop();

        return () => {
            handleStop();
        };
    }, [location.pathname]);

    return <>{children}</>;
};

export default NProgressBar;