import * as React from "react" ; import { counter , getId , getPrefix , IdSourceType , source } from "./context" ; returns { String } see uid type SeedGenerator = ( id : any ) => string ; const generateUID = ( context ) => { const quartz = context || counter ; const prefix = getPrefix ( quartz ) ; const id = getId ( quartz ) ; const uid = prefix + id ; const gen = ( item ) => uid + quartz . uid ( item ) ; return { uid , gen } ; } ; const useUIDState = ( ) => { if ( process . env . NODE_ENV !== "production" ) { if ( ! ( 'useContext' in React ) ) { throw new Error ( 'Hooks API requires React 16.8+' ) ; } } return React . useState ( generateUID ( React . useContext ( source ) ) ) ; } ; see UIDConsumer see https example export const useUID = ( ) : string => { const [ { uid } ] = useUIDState ( ) ; return uid ; } ; see UIDConsumer see https example export const useUIDSeed = ( ) : SeedGenerator => { const [ { gen } ] = useUIDState ( ) ; return gen ; } ;