mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-28 07:51:05 +00:00
24 lines
616 B
JavaScript
24 lines
616 B
JavaScript
'use client';
|
|
import { useState } from 'react';
|
|
import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect.mjs';
|
|
import { randomId } from '../utils/random-id/random-id.mjs';
|
|
import { useReactId } from './use-react-id.mjs';
|
|
|
|
function useId(staticId) {
|
|
const reactId = useReactId();
|
|
const [uuid, setUuid] = useState(reactId);
|
|
useIsomorphicEffect(() => {
|
|
setUuid(randomId());
|
|
}, []);
|
|
if (typeof staticId === "string") {
|
|
return staticId;
|
|
}
|
|
if (typeof window === "undefined") {
|
|
return reactId;
|
|
}
|
|
return uuid;
|
|
}
|
|
|
|
export { useId };
|
|
//# sourceMappingURL=use-id.mjs.map
|