UNPKG

monday-ui-react-core

Version:

Official monday.com UI resources for application development in React.js

23 lines (17 loc) 456 B
import { useRef, useCallback } from "react"; export default function useRefWithCallback(onMount, onUnmount) { const nodeRef = useRef(null); const setRef = useCallback( node => { if (nodeRef.current && onUnmount) { onUnmount(nodeRef.current); } nodeRef.current = node; if (nodeRef.current && onMount) { onMount(nodeRef.current); } }, [onMount, onUnmount] ); return [nodeRef, setRef]; }