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

41 lines (38 loc) 943 B
import { useMemo } from 'react'; /** * Private symbol that is intentionally not exported from this file. */ const privateKey = Symbol('DraggableData'); /** * Data that is attached to drags. The same data is used for the `draggable()` * and `dropTargetForElements()` calls related to a `<Draggable>` instance. */ /** * Checks if the passed data satisfies `DraggableData` using the private symbol. */ export function isDraggableData(data) { return data[privateKey] === true; } /** * Adds the private symbol to the passed data. * * The symbol allows us to quickly check if an object satisfies `DraggableData`. */ export function useDraggableData({ draggableId, droppableId, getIndex, contextId, type }) { return useMemo(() => { return { [privateKey]: true, draggableId, droppableId, getIndex, contextId, type }; }, [draggableId, droppableId, getIndex, contextId, type]); }