Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

useCallbackRef.js 791B

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