OneLauncher-Cracked/apps/onelauncher/frontend/src/hooks/usePopState.ts
emirsassan 855d421eaa feat: global game settings and notifications
notification system needs some work still
2025-06-26 20:48:48 +03:00

20 lines
549 B
TypeScript

import { useLocation } from '@tanstack/react-router';
import { useEffect, useRef } from 'react';
export default function usePopState(onRouteChange: void | any) {
const location = useLocation();
const prevLocationRef = useRef(location);
useEffect(() => {
const prevLocation = prevLocationRef.current;
// Only run if the pathname actually changed
if (prevLocation.pathname !== location.pathname)
onRouteChange?.({
from: prevLocation,
to: location,
});
prevLocationRef.current = location;
}, [location, onRouteChange]);
}