UNPKG

react-usehooks-ts

Version:

A collections of typescript supported react Custom hooks

38 lines (37 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useDetectIncognito = void 0; const react_1 = require("react"); const utils_1 = require("../utils"); const useDetectIncognito = () => { const [isIncognito, setIsIncognito] = (0, react_1.useState)(false); const [isDetectingIncognito, setIsDetectingIncognito] = (0, react_1.useState)(true); (0, react_1.useEffect)(() => { const script = document.createElement("script"); script.src = utils_1.detectIncognitoScriptLink; script.async = true; script.onload = () => { const detectIncognitoFunction = window.detectIncognito; if (!detectIncognitoFunction) { console.error("detectIncognito is not available in the window object."); setIsDetectingIncognito(false); return; } detectIncognitoFunction() .then(({ isPrivate }) => { setIsIncognito(isPrivate); setIsDetectingIncognito(false); }) .catch((error) => { console.error("Error while detecting Incognito Mode:", error); setIsDetectingIncognito(false); }); }; document.body.appendChild(script); return () => { document.body.removeChild(script); }; }, []); return [isIncognito, isDetectingIncognito]; }; exports.useDetectIncognito = useDetectIncognito;