Skip to content

Commit c40f68a

Browse files
committed
refactor(ui): use React's useId
1 parent cdcdf6e commit c40f68a

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

packages/hooks/src/useId.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
import { useMemo } from 'react';
1+
import { useId as useIdByReact } from 'react';
22

3-
const STR = 'abcdefghijklmnopqrstuvwxyz';
4-
5-
const ID = [-1];
63
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-
}, []);
4+
return useIdByReact();
215
}
22-
useId.PREFIX = 'ID';

0 commit comments

Comments
 (0)