UNPKG

@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-migration

Version:

An optional Pragmatic drag and drop package that enables rapid migration from react-beautiful-dnd to Pragmatic drag and drop

27 lines (26 loc) 600 B
import { useEffect, useState } from 'react'; const noop = () => {}; function createCleanupManager() { let cleanupFn = noop; const setCleanupFn = newCleanupFn => { cleanupFn = newCleanupFn; }; const runCleanupFn = () => { cleanupFn(); cleanupFn = noop; }; return { setCleanupFn, runCleanupFn }; } export function useCleanupFn() { const [cleanupManager] = useState(createCleanupManager); /** * Run the cleanup function on unmount. */ useEffect(() => { return cleanupManager.runCleanupFn; }, [cleanupManager.runCleanupFn]); return cleanupManager; }