Skip to content

Commit f2ac626

Browse files
committed
Another attempt
1 parent 14a55e3 commit f2ac626

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/core-react-interop.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import { shortuuid } from "./core-utils";
22
const React = require("react");
33

4-
export function useUniqueId(ssrEnabled: boolean) {
5-
if (ssrEnabled) {
6-
if (React.version.startsWith("18") && typeof React.useId !== "undefined") {
7-
return `s${React.useId().replace(/\:/g, "")}`;
8-
}
9-
4+
function getIdFn() {
5+
if (React.version.startsWith("18") && typeof React.useId !== "undefined") {
6+
return React.useId;
7+
}
8+
// @ts-ignore
9+
if (typeof React.unstable_useOpaqueIdentifier !== "undefined") {
10+
console.log("React 17 legacy");
1011
// @ts-ignore
11-
if (typeof React.unstable_useOpaqueIdentifier !== "undefined") {
12-
console.log("React 17 legacy");
13-
// @ts-ignore
14-
return `s${React.unstable_useOpaqueIdentifier().replace(/\:/g, "")}`;
15-
}
12+
return React.unstable_useOpaqueIdentifier;
1613
}
14+
return () => `s${shortuuid()}`;
15+
}
1716

18-
return `s${shortuuid()}`;
17+
export function useUniqueId(ssrEnabled: boolean) {
18+
const idFn = getIdFn();
19+
return `s${idFn().replace(/\:/g, "")}`;
1920
}

0 commit comments

Comments
 (0)