File tree Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Original file line number Diff line number Diff line change 1
1
import { shortuuid } from "./core-utils" ;
2
2
const React = require ( "react" ) ;
3
3
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" ) ;
10
11
// @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 ;
16
13
}
14
+ return ( ) => `s${ shortuuid ( ) } ` ;
15
+ }
17
16
18
- return `s${ shortuuid ( ) } ` ;
17
+ export function useUniqueId ( ssrEnabled : boolean ) {
18
+ const idFn = getIdFn ( ) ;
19
+ return `s${ idFn ( ) . replace ( / \: / g, "" ) } ` ;
19
20
}
You can’t perform that action at this time.
0 commit comments