UNPKG

@mantine/hooks

Version:

A collection of 50+ hooks for state and UI management

1 lines 824 B
{"version":3,"file":"use-id.mjs","names":["useId","useReactId"],"sources":["../../src/use-id/use-id.ts"],"sourcesContent":["import { useId as useReactId, useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\nimport { randomId } from '../utils';\n\nexport function useId(staticId?: string) {\n const reactId = useReactId();\n const [uuid, setUuid] = useState(`mantine-${reactId.replace(/:/g, '')}`);\n\n useIsomorphicEffect(() => {\n setUuid(randomId());\n }, []);\n\n if (typeof staticId === 'string') {\n return staticId;\n }\n\n return uuid;\n}\n"],"mappings":";;;;;AAIA,SAAgBA,QAAM,UAAmB;CAEvC,MAAM,CAAC,MAAM,WAAW,SAAS,WADjBC,OAAY,CACwB,QAAQ,MAAM,GAAG,GAAG;AAExE,2BAA0B;AACxB,UAAQ,UAAU,CAAC;IAClB,EAAE,CAAC;AAEN,KAAI,OAAO,aAAa,SACtB,QAAO;AAGT,QAAO"}