import { nanoid } from "nanoid" import { useMemo } from "react" const storageKey = "web_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 = nanoid() sessionStorage.setItem(storageKey, currentSessionId) } return currentSessionId }, []) return sessionId }