{"version":3,"file":"useWatchPathname.mjs","names":[],"sources":["../../../src/hooks/useWatchPathname.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\ntype Callback = (pathname: string) => void;\n\nexport const useWatchPathname = (callback: Callback) => {\n  const storedHref = useRef<string | undefined>(\n    typeof location === \"undefined\" ? undefined : location.href,\n  );\n\n  useEffect(() => {\n    if (typeof location === \"undefined\") {\n      return;\n    }\n\n    /** Need to poll here, because no appropriate browser API exists */\n    const checker = setInterval(() => {\n      const href = location.href;\n      if (href !== storedHref.current) {\n        const url = new URL(href);\n        callback(url.pathname + url.search);\n        storedHref.current = href;\n      }\n    }, 50);\n\n    return () => {\n      clearInterval(checker);\n    };\n  }, [storedHref]);\n};\n"],"mappings":";;;;AAIA,IAAa,oBAAoB,aAAuB;CACtD,MAAM,aAAa,OACjB,OAAO,aAAa,cAAc,KAAA,IAAY,SAAS,IACzD;CAEA,gBAAgB;EACd,IAAI,OAAO,aAAa,aACtB;;EAIF,MAAM,UAAU,kBAAkB;GAChC,MAAM,OAAO,SAAS;GACtB,IAAI,SAAS,WAAW,SAAS;IAC/B,MAAM,MAAM,IAAI,IAAI,IAAI;IACxB,SAAS,IAAI,WAAW,IAAI,MAAM;IAClC,WAAW,UAAU;GACvB;EACF,GAAG,EAAE;EAEL,aAAa;GACX,cAAc,OAAO;EACvB;CACF,GAAG,CAAC,UAAU,CAAC;AACjB"}