Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

29 wiersze
741 B

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