react-dnd
Version:
Drag and Drop for React
23 lines (20 loc) • 706 B
text/typescript
import { useMemo } from 'react'
import { TargetConnector } from '../../internals/index.js'
import type { DropTargetOptions } from '../../types/index.js'
import { useDragDropManager } from '../useDragDropManager.js'
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect.js'
export function useDropTargetConnector(
options: DropTargetOptions,
): TargetConnector {
const manager = useDragDropManager()
const connector = useMemo(
() => new TargetConnector(manager.getBackend()),
[manager],
)
useIsomorphicLayoutEffect(() => {
connector.dropTargetOptions = options || null
connector.reconnect()
return () => connector.disconnectDropTarget()
}, [options])
return connector
}