UNPKG

@loke/ui

Version:
17 lines (16 loc) • 502 B
// src/hooks/use-id/id.tsx import { useLayoutEffect } from "@loke/ui/use-layout-effect"; import React, { useState } from "react"; var useReactId = React[" useId ".trim().toString()] || (() => { return; }), count = 0; function useId(deterministicId) { let [id, setId] = useState(useReactId()); return useLayoutEffect(() => { if (!deterministicId) setId((reactId) => reactId ?? String(count++)); }, [deterministicId]), deterministicId || (id ? `loke-${id}` : ""); } export { useId };