UNPKG

@mantine/hooks

Version:

A collection of 50+ hooks for state and UI management

1 lines 834 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,MACkC,EAAE,QAAQ,MAAM,EAAE,GAAG;CAEvE,0BAA0B;EACxB,QAAQ,SAAS,CAAC;CACpB,GAAG,CAAC,CAAC;CAEL,IAAI,OAAO,aAAa,UACtB,OAAO;CAGT,OAAO;AACT"}