Connecting monitor.getClientOffset to a DropTarget does not refresh props
See original GitHub issueI created a DropTarget and connected getClientOffset as follows:
targetCollect = function (connect, monitor) {
return {
connectDropTarget: connect.dropTarget(),
isOver: monitor.isOver(),
clientOffset: monitor.getClientOffset()
}
}
However, when moving drag within the component, the target does not receive updated props with each wiggle of the mouse (only on enter and exit). The target spec’s hover is called however repeatedly. Is there a reason that the clientOffset prop is not injected each time it is changed?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:14
- Comments:22 (3 by maintainers)
Top Results From Across the Web
Next steps with React Drag and Drop -- Adding a Drop Target
In this post, we are going to talk about handling drop events to make sure that ... const workDropTarget = { hover: function(props,...
Read more >ReactDnD sorting elements not updating on Dragging
DropTarget ; var Card = React.createClass({ render: function() { var connectDragSource = this.props.
Read more >gaearon/react-dnd - Gitter
So basically what I think is happening is the high order components are not forwarding the default props to the Child Component rendered...
Read more >[Solved]-React DnD showing entire list when dragging-Reactjs
What you should do is that you should have unique ids of each single item ... ITEM, { hover: (props, monitor, component) =>...
Read more >Sortable Targets with React DnD
Just render the Containers on the screen and give them some props. What props? Well, definitely the Container should know which cards it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1. Running into this and wasting a lot of time trying to understand why getClientOffset() works fine in canDrop() - which does get called repeatedly… - but no way to forward to my control ‘where’ over the item we are. I need to be able to insert above and below a treenode, not just “on” it. canDrop() has no way that I can find that lets me actually tell my component which of the many “types” of drops the node has so that my control can redisplay accordingly. Changing the prop in canDrop resulted in an error. Subscribing to onMouseMove doesn’t work during drag and drop operations. This has been a huge waste of time so far…any help would be appreciated.
@ibash, would you mind posting a gist of what you did to solve your problem?
Btw. one other really ugly hack around this issue can be to send in the coordinates as state from
dropTarget.hover()
:Of course there are tons of more correct ways to do this that would avoid abusing of setState like that. But at least this little hack is very condensed and may do the job until this issue is eventually fixed. It lets you hack around the bug without changing other components and/or files and without relying on library internals.
Edit: this is basically the same as noah79 does, I just didn’t read his code before now.