feat: auth race condition & optimize ApolloFactory & too many pageview (#602)

This commit is contained in:
Jérémy M
2023-07-11 19:50:25 +02:00
committed by GitHub
parent 55576cb638
commit 718ad721cf
12 changed files with 69 additions and 44 deletions

View File

@ -1,17 +1,26 @@
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import usePrevious from '@/utils/hooks/usePrevious';
import { useEventTracker } from './useEventTracker';
export function useTrackPageView() {
const location = useLocation();
const previousLocation = usePrevious(location);
const eventTracker = useEventTracker();
useEffect(() => {
eventTracker('pageview', {
location: {
pathname: location.pathname,
},
});
}, [location, eventTracker]);
// Avoid lot of pageview events enven if the location is the same
if (
!previousLocation?.pathname ||
previousLocation?.pathname !== location.pathname
) {
eventTracker('pageview', {
location: {
pathname: location.pathname,
},
});
}
}, [location, eventTracker, previousLocation?.pathname]);
}