Skip to content

Commit 5ca88c3

Browse files
authored
fix(utilities): prevent "undefined" string return value for useId with React 17 (#706)
1 parent 71b718f commit 5ca88c3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/utilities/src/utils/useId.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,14 @@ let idCounter = 0;
1616
*
1717
* @returns A generated ID that can be passed to accessibility attributes
1818
*/
19-
export const useId = (id?: any) => `${useReachId(id)}` || `id:${idCounter++}`;
19+
export const useId = (id?: any) => {
20+
let retVal = useReachId(id);
21+
22+
if (retVal === undefined || retVal === null) {
23+
retVal = `id:${idCounter++}`;
24+
} else {
25+
retVal = `${retVal}`;
26+
}
27+
28+
return retVal;
29+
};

0 commit comments

Comments
 (0)