1 line
815 B
JSON
1 line
815 B
JSON
{"ast":null,"code":"import { useState } from 'react';\n/**\n * A convenience hook around `useState` designed to be paired with\n * the component [callback ref](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) api.\n * Callback refs are useful over `useRef()` when you need to respond to the ref being set\n * instead of lazily accessing it in an effect.\n *\n * ```ts\n * const [element, attachRef] = useCallbackRef<HTMLDivElement>()\n *\n * useEffect(() => {\n * if (!element) return\n *\n * const calendar = new FullCalendar.Calendar(element)\n *\n * return () => {\n * calendar.destroy()\n * }\n * }, [element])\n *\n * return <div ref={attachRef} />\n * ```\n */\n\nexport default function useCallbackRef() {\n return useState(null);\n}","map":null,"metadata":{},"sourceType":"module"} |