question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

endDrag function on component not being called when item is removed from DOM

See original GitHub issue

I’m using react-dnd for a kanban board app (trello like), and when moving a card to another list (thus unmounting source component during drag), the endDrag function is not called, as the listeners for DragDropStore are removed on unmount.

As a workaround, I’ve added a _lastDraggedItem and getLastDraggedItem to DragDropStore, and subscribed to DragDropStore on parent component, handling the endDrag there. As we clear the variables in DragDropStore before firing the DRAG_END event, I couldn’t find any other way to get dragged item.

The reason I’m not using DROP event is, it’s not fired when the item is dropped outside of browser window, only DRAG_END is fired.

It works but it’s messy, breaking the beginDrag & endDrag symmetry.

Are there any other ways to trigger a function on endDrag, with access to dragged item?

Or if is this a valid usecase for others, should we add my workaround to the repo?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
remcotakcommented, Apr 12, 2017

@gaearon I’m having almost the same issue as this one. I have a simple sortable list that gets controlled by Redux. The sorting of the list is done almost the same way as this example.

Except the problem is, items can get removed from that list. The state gets updated with a complete new list retrieved from the store with less items. The unmount of the items happens and the dragEnd is not triggered.

The problem only occurs when a new list is presented with an item missing

0reactions
Fineccommented, Mar 6, 2019

Maybe this can help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Components | Video.js
A component is a JavaScript object that has the following features: An associated DOM element, in almost all cases. An association to a...
Read more >
ReactJS Wrong Component gets removed from DOM
What I would like to happen (or what I think should happen) is when removeShop gets called, that shop gets removed from the...
Read more >
Components | Video.js
A component is a JavaScript object that has the following features: An associated DOM element, in almost all cases. An association to a...
Read more >
useDrag - React DnD
The useDrag hook provides a way to wire your component into the DnD system ... of draggable being generated, the item object representing...
Read more >
useDrop - React DnD
The useDrop hook provides a way for you to wire in your component into the DnD system as a drop ... Called when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found