Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F99447306
useForkRef.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
Fri, Jan 24, 15:50
Size
635 B
Mime Type
text/x-java
Expires
Sun, Jan 26, 15:50 (2 d)
Engine
blob
Format
Raw Data
Handle
23797305
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
useForkRef.js
View Options
import
*
as
React
from
'react'
;
import
setRef
from
'./setRef'
;
export
default
function
useForkRef
(...
refs
)
{
/**
* This will create a new function if the refs passed to this hook change and are all defined.
* This means react will call the old forkRef with `null` and the new forkRef
* with the ref. Cleanup naturally emerges from this behavior.
*/
return
React
.
useMemo
(()
=>
{
if
(
refs
.
every
(
ref
=>
ref
==
null
))
{
return
null
;
}
return
instance
=>
{
refs
.
forEach
(
ref
=>
{
setRef
(
ref
,
instance
);
});
};
// eslint-disable-next-line react-hooks/exhaustive-deps
},
refs
);
}
Event Timeline
Log In to Comment