Track sessionId

This commit is contained in:
Linus Flood
2024-12-03 11:46:43 +01:00
parent 9db02488d8
commit b9111511b7
7 changed files with 55 additions and 7 deletions

17
hooks/useSessionId.ts Normal file
View File

@@ -0,0 +1,17 @@
import { useMemo } from "react"
import { v4 as uuidv4 } from "uuid"
const storageKey = "sessionId"
export function useSessionId(): string {
const sessionId = useMemo(() => {
let currentSessionId = sessionStorage.getItem(storageKey)
if (!currentSessionId) {
currentSessionId = uuidv4()
sessionStorage.setItem(storageKey, currentSessionId)
}
return currentSessionId
}, [])
return sessionId
}