-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-type: minor
- Loading branch information
Andrea Rosci
authored and
Andrea Rosci
committed
Nov 25, 2024
1 parent
78eb946
commit 52293a9
Showing
3 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useMemo } from 'react'; | ||
|
||
export const useRandomUUID = (): string => { | ||
const generateUUID = () => { | ||
if (typeof crypto?.randomUUID === 'function') { | ||
return crypto.randomUUID(); | ||
} | ||
|
||
const template = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; | ||
return template.replace(/x/g, () => | ||
Math.floor(Math.random() * 16).toString(16), | ||
); | ||
}; | ||
|
||
return useMemo(() => generateUUID(), []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters