fix: update useTabUuid hooks

This commit is contained in:
yassinedorbozgithub 2025-01-29 17:01:06 +01:00
parent 09ec35f520
commit 50406af6c2

View File

@ -6,25 +6,23 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { useEffect, useRef } from "react"; import { useRef } from "react";
import { generateId } from "@/utils/generateId"; import { generateId } from "@/utils/generateId";
export const useTabUuid = (key: string = "tab_uuid") => { const getOrCreateTabId = () => {
const tabUuidRef = useRef<string | null>(null); let tabId = sessionStorage.getItem("tab_uuid");
useEffect(() => { if (!tabId) {
const storedUuid = sessionStorage.getItem(key); tabId = generateId();
sessionStorage.setItem("tab_uuid", tabId);
}
if (storedUuid) { return tabId;
tabUuidRef.current = storedUuid; };
} else {
const newUuid = generateId();
sessionStorage.setItem(key, newUuid); export const useTabUuid = () => {
tabUuidRef.current = newUuid; const tabUuidRef = useRef<string | null>(getOrCreateTabId());
}
}, []);
return tabUuidRef; return tabUuidRef;
}; };