Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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. }