We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
useId
1 parent cdcdf6e commit c40f68aCopy full SHA for c40f68a
packages/hooks/src/useId.ts
@@ -1,22 +1,5 @@
1
-import { useMemo } from 'react';
+import { useId as useIdByReact } from 'react';
2
3
-const STR = 'abcdefghijklmnopqrstuvwxyz';
4
-
5
-const ID = [-1];
6
export function useId(): string {
7
- return useMemo(() => {
8
- const reduce = (index: number) => {
9
- const charIndex = ID[index] ?? -1;
10
- if (charIndex + 1 === STR.length) {
11
- ID[index] = 0;
12
- reduce(index + 1);
13
- } else {
14
- ID[index] = charIndex + 1;
15
- }
16
- };
17
- reduce(0);
18
19
- return `${useId.PREFIX}${ID.map((charIndex) => STR[charIndex]).join('')}`;
20
- }, []);
+ return useIdByReact();
21
}
22
-useId.PREFIX = 'ID';
0 commit comments