UNPKG

@trellixio/roaster-coffee

Version:
24 lines (23 loc) 680 B
import * as React from 'react'; import { guid } from '../guid'; /** * A custom React hook that generates a unique ID prefixed with roaster. * * @returns A unique ID string prefixed with roaster. */ function useRoasterId() { const [uid, setUid] = React.useState(''); React.useEffect(() => { setUid(`roaster-${guid()}`); }, []); return uid; } /** * A custom React hook that returns a unique ID if provided or a genereated ID prefixed with roaster. * * @param staticId - The static ID to be used, if provided. * @returns A unique ID string. */ export function useUid(staticId) { return typeof staticId === 'string' ? staticId : useRoasterId(); }