1 | ;
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = useCallbackRef;
|
5 |
|
6 | var _react = require("react");
|
7 |
|
8 | /**
|
9 | * A convenience hook around `useState` designed to be paired with
|
10 | * the component [callback ref](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) api.
|
11 | * Callback refs are useful over `useRef()` when you need to respond to the ref being set
|
12 | * instead of lazily accessing it in an effect.
|
13 | *
|
14 | * ```ts
|
15 | * const [element, attachRef] = useCallbackRef<HTMLDivElement>()
|
16 | *
|
17 | * useEffect(() => {
|
18 | * if (!element) return
|
19 | *
|
20 | * const calendar = new FullCalendar.Calendar(element)
|
21 | *
|
22 | * return () => {
|
23 | * calendar.destroy()
|
24 | * }
|
25 | * }, [element])
|
26 | *
|
27 | * return <div ref={attachRef} />
|
28 | * ```
|
29 | *
|
30 | * @category refs
|
31 | */
|
32 | function useCallbackRef() {
|
33 | return (0, _react.useState)(null);
|
34 | } |
\ | No newline at end of file |