Skip to content

Side-effects in drop and endDrag #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jamesdbrock opened this issue Feb 15, 2020 · 0 comments
Closed

Side-effects in drop and endDrag #10

jamesdbrock opened this issue Feb 15, 2020 · 0 comments

Comments

@jamesdbrock
Copy link
Member

jamesdbrock commented Feb 15, 2020

Something I have learned:

On a drop event, you may want to call back up the render tree to change some props or state.

Do your prop-changing side-effects in DragSourceProps.endDrag, not in DropTargetProps.drop.

During a drag, React.Basic.ReactDND will make component state changes to reflect the state of the drag. DropTargetProps.drop will fire before all of the dragging state changes have completed. DragSourceProps.endDrag will fire after all of the dragging stage changes have completed. If you change the props with a side-effect before the dragging state changes have completed, then the dnd components might get unmounted while they are still doing state changes to finish the drag. In that event, you will see runtime exceptions like this:

Uncaught Invariant Violation: Expected to find a valid source.
Uncaught Invariant Violation: Cannot call hover after drop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant