@devcycle/nextjs-sdk
Version:
The Next.js SDK for DevCycle!
23 lines • 1.29 kB
JavaScript
import { useEffect, useRef } from 'react';
import { clearDebugUserCookie } from '../../common/actions';
export const useClearUserDebugCookie = () => {
const hasClearedCookieRef = useRef(false);
// Clear the debug user cookie on page refresh (not on client-side navigation) if it exists
// This runs only on mount, which happens on refresh but not on client-side navigation
useEffect(() => {
var _a, _b, _c;
if (!hasClearedCookieRef.current) {
hasClearedCookieRef.current = true;
// Check if this is a page refresh vs client-side navigation
// Using both the deprecated and modern Navigation API for compatibility
const navEntries = ((_a = window.performance) === null || _a === void 0 ? void 0 : _a.getEntriesByType('navigation')) || [];
const navEntry = navEntries[0];
const isRefresh = ((_c = (_b = window.performance) === null || _b === void 0 ? void 0 : _b.navigation) === null || _c === void 0 ? void 0 : _c.type) === 1 ||
(navEntry === null || navEntry === void 0 ? void 0 : navEntry.type) === 'reload';
if (isRefresh) {
clearDebugUserCookie();
}
}
}, []);
};
//# sourceMappingURL=useClearUserDebugCookie.js.map