Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102279631
useId.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 19, 01:30
Size
1 KB
Mime Type
text/x-java
Expires
Fri, Feb 21, 01:30 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24322756
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
useId.js
View Options
import
*
as
React
from
'react'
;
let
globalId
=
0
;
function
useGlobalId
(
idOverride
)
{
const
[
defaultId
,
setDefaultId
]
=
React
.
useState
(
idOverride
);
const
id
=
idOverride
||
defaultId
;
React
.
useEffect
(()
=>
{
if
(
defaultId
==
null
)
{
// Fallback to this default id when possible.
// Use the incrementing value for client-side rendering only.
// We can't use it server-side.
// If you want to use random values please consider the Birthday Problem: https://en.wikipedia.org/wiki/Birthday_problem
globalId
+=
1
;
setDefaultId
(
`
mui
-
$
{
globalId
}
`
);
}
},
[
defaultId
]);
return
id
;
}
// eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
const
maybeReactUseId
=
React
[
'useId'
+
''
];
/**
*
* @example <div id={useId()} />
* @param idOverride
* @returns {string}
*/
export
default
function
useId
(
idOverride
)
{
if
(
maybeReactUseId
!==
undefined
)
{
const
reactId
=
maybeReactUseId
();
return
idOverride
!=
null
?
idOverride
:
reactId
;
}
// eslint-disable-next-line react-hooks/rules-of-hooks -- `React.useId` is invariant at runtime.
return
useGlobalId
(
idOverride
);
}
Event Timeline
Log In to Comment