Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100868667
useRefWithInitialValueFactory.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
Mon, Feb 3, 11:04
Size
653 B
Mime Type
text/x-java
Expires
Wed, Feb 5, 11:04 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24041003
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
useRefWithInitialValueFactory.js
View Options
import
{
useRef
}
from
'react'
;
var
dft
=
Symbol
(
'default value sigil'
);
/**
* Exactly the same as `useRef` except that the initial value is set via a
* factroy function. Useful when the default is relatively costly to construct.
*
* ```ts
* const ref = useRefWithInitialValueFactory<ExpensiveValue>(() => constructExpensiveValue())
*
* ```
*
* @param initialValueFactory A factory function returning the ref's default value
* @category refs
*/
export
default
function
useRefWithInitialValueFactory
(
initialValueFactory
)
{
var
ref
=
useRef
(
dft
);
if
(
ref
.
current
===
dft
)
{
ref
.
current
=
initialValueFactory
();
}
return
ref
;
}
Event Timeline
Log In to Comment