UNPKG

@ducor/hooks

Version:

A collection of useful React hooks for building modern web applications. Includes hooks for clipboard operations, window events, intervals, timeouts, and more.

14 lines (13 loc) 451 B
import { useRef } from 'react'; // https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript const uuidv4 = () => { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8; return v.toString(16); }); }; const useUUID = () => { const uuidRef = useRef(uuidv4()); return uuidRef.current; }; export default useUUID;