import { useMemo } from "react" import { v4 as uuidv4 } from "uuid" const storageKey = "sessionId" export function useSessionId(): string | null { const sessionId = useMemo(() => { if (typeof window === "undefined") { // Return null if running on the server return null } let currentSessionId = sessionStorage.getItem(storageKey) if (!currentSessionId) { currentSessionId = uuidv4() sessionStorage.setItem(storageKey, currentSessionId) } return currentSessionId }, []) return sessionId }