Vercel/src/utility/usePathnames.ts
Sam Becker df11a86181 Init
2023-09-05 09:00:57 -05:00

21 lines
487 B
TypeScript

import { useEffect, useRef } from 'react';
import { usePathname } from 'next/navigation';
const usePathnames = () => {
const pathname = usePathname();
const currentRef = useRef<string>();
const previousRef = useRef<string>();
useEffect(() => {
previousRef.current = currentRef.current;
currentRef.current = pathname;
}, [pathname]);
return {
currentPathname: currentRef.current,
previousPathname: previousRef.current,
};
};
export default usePathnames;