react-dnd / react-dnd

Drag and Drop for React

Home Page:http://react-dnd.github.io/react-dnd

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught Invariant Violation: Expected an existing source.

paralin opened this issue · comments

I have a draggable component in my app within a react-window virtualized list:

    const collect = useCallback(
      (monitor: DragSourceMonitor) => ({ isDragging: monitor.isDragging() }),
      [],
    )

    // setup the drag/drop drag source
    const [{ isDragging }, drag] = useDrag({
      item: handleDragStart,
      type: MyDndItemType,
      canDrag: !!onDragStart || selected,
      // end: onDragEnd,
      collect,
    })

When the component is unmounted, this invariant is triggered:

invariant(this.getSource(sourceId), 'Expected an existing source.')

I'm not doing anything special, just removing the component from the page.

How can I fix this error?