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.

You may not call monitor.canDrop() inside your canDrop() implementation

See original GitHub issue

In canDrop, before returning false, we want to update state to display notification about why it can’t be dropped, but got this error:

Uncaught Error: You may not call monitor.canDrop() inside your canDrop() implementation. Read more: http://react-dnd.github.io/react-dnd/docs-drop-target-monitor.html

Is there a way to deal with it or may be a callback function?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
wuweiweiwucommented, Mar 12, 2018

@zourbuth this issue is confirmed and I think its due to how we bind this when we create DropTarget. I will have to investigate more later

Seems related to https://github.com/react-dnd/react-dnd/issues/265

I will consider possibly writing so canDrop to allow a callback. Or possibly passing the same object to onDragStateChanged. Seems to be a tricky issue

1reaction
kohsahcommented, Nov 19, 2019

I did a hacky workaround for this issue, since showing a rejection notification in canDrop() was triggered multiple times, so i got dozens of rejection notifications when only one was neccessary.

so i have a variable in state which just records the last success or failure of canDrop.

then in onDragStateChanged if its not isDragging i check the variable from state, and display the error notif, if it was a failure. For a complete drag action, onDragStateChanged is triggered once so it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - You may not call monitor.canDrop() inside your ...
In canDrop , before returning false , we want to update state to display notification about why it can't be dropped, but got...
Read more >
Checking canDrop() result - react dnd - Stack Overflow
My question now is, when the drop action fails, I want to display a message like "You can't drop this card here because...
Read more >
useDrop - React DnD
This method will not be called if canDrop() is defined and returns false . hover(item, monitor) : Optional. Called when an item is...
Read more >
DropTarget - React-dnd - Breword 文档集合
Note: You may not call monitor.canDrop() inside this method. The spec offers no methods to handle enter or leave events by purpose. Instead,...
Read more >
Rethinking In React DnD - Medium
React DnD is hard to learn if you have never used it before. ... canDrop(),}))export default class PolicyComponents extends React.
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