Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F105324875
useCallbackRef.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
Sun, Mar 16, 08:10
Size
741 B
Mime Type
text/x-java
Expires
Tue, Mar 18, 08:10 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24960148
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
useCallbackRef.js
View Options
import { useState } from 'react';
/**
* A convenience hook around `useState` designed to be paired with
* the component [callback ref](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) api.
* Callback refs are useful over `useRef()` when you need to respond to the ref being set
* instead of lazily accessing it in an effect.
*
* ```ts
* const [element, attachRef] = useCallbackRef<HTMLDivElement>()
*
* useEffect(() => {
* if (!element) return
*
* const calendar = new FullCalendar.Calendar(element)
*
* return () => {
* calendar.destroy()
* }
* }, [element])
*
* return <div ref={attachRef} />
* ```
*
* @category refs
*/
export default function useCallbackRef() {
return useState(null);
}
Event Timeline
Log In to Comment