UNPKG

rooks

Version:

Essential React custom hooks ⚓ to super charge your components!

17 lines (16 loc) 581 B
import { useCallback, useState } from "react"; /** * useRefElement hook for React * Helps bridge gap between callback ref and state * Manages the element called with callback ref api using state variable * @returns {[RefElementOrNull, (element: HTMLElementOrNull) => void]} * @see https://react-hooks.org/docs/useRefElement */ function useRefElement() { var _a = useState(null), refElement = _a[0], setRefElement = _a[1]; var ref = useCallback(function (element) { setRefElement(element); }, []); return [ref, refElement]; } export { useRefElement };