mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
34 lines
812 B
JavaScript
34 lines
812 B
JavaScript
"use strict";
|
|
|
|
exports.__esModule = true;
|
|
exports.default = useCallbackRef;
|
|
|
|
var _react = require("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
|
|
*/
|
|
function useCallbackRef() {
|
|
return (0, _react.useState)(null);
|
|
} |