import { useOnce, useMutable } from '../../react' import { dragEvent } from './index' import { isF } from '../utils' import type { ReactNode } from 'react' import type { DragArg, DragState } from './types' export const useDrag = (arg: DragArg) => { if (isF(arg)) arg = { drag: arg } const memo = useMutable(arg) return useOnce(() => dragEvent(memo as any)) } export default useDrag export interface DragProps extends Partial> { children(self: DragState): ReactNode } export const Drag = (props: DragProps) => { const { children, ...other } = props return children(useDrag(other)) }