/* eslint-disable react-refresh/only-export-components */ import React, { createContext, useState, useContext, useEffect, ReactNode } from 'react'; import { useLocation } from 'react-router-dom'; interface IPathnameContextProps { pathname: string; prevPathname: string | undefined; } const PathnameContext = createContext(undefined); const PathnameProvider = ({ children }: { children: ReactNode }) => { const { pathname } = useLocation(); const [prevPathname, setPrevPathname] = useState(undefined); useEffect(() => { setPrevPathname(() => { return pathname; }); }, [pathname]); return ( {children} ); }; const usePathname = (): IPathnameContextProps => { const context = useContext(PathnameContext); if (!context) { throw new Error('usePathname must be used within a PathnameProvider'); } return context; }; export { PathnameProvider, usePathname };