Move device ID logic from @multica/store (Zustand persist) into a simple useDeviceId hook in the web app. SSR returns empty string, client reads/writes localStorage directly — no hydration mismatch, no suppressHydrationWarning needed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
19 lines
412 B
TypeScript
19 lines
412 B
TypeScript
import { useState, useEffect } from "react"
|
|
import { v7 as uuidv7 } from "uuid"
|
|
|
|
const STORAGE_KEY = "multica-device-id"
|
|
|
|
export function useDeviceId(): string {
|
|
const [deviceId, setDeviceId] = useState("")
|
|
|
|
useEffect(() => {
|
|
let id = localStorage.getItem(STORAGE_KEY)
|
|
if (!id) {
|
|
id = uuidv7()
|
|
localStorage.setItem(STORAGE_KEY, id)
|
|
}
|
|
setDeviceId(id)
|
|
}, [])
|
|
|
|
return deviceId
|
|
}
|