-
Notifications
You must be signed in to change notification settings - Fork 2k
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
useDrag() Hook Changes #3114
useDrag() Hook Changes #3114
Conversation
* spec.type is required * spec.item is optional, and may be an object or function. This replaces the spec.begin() function.
Codecov Report
@@ Coverage Diff @@
## main #3114 +/- ##
==========================================
+ Coverage 56.47% 56.55% +0.08%
==========================================
Files 262 263 +1
Lines 3853 3865 +12
Branches 773 776 +3
==========================================
+ Hits 2176 2186 +10
- Misses 1676 1678 +2
Partials 1 1
|
@darthtrevino It might be good idea to put deprecated warning when someone tries to use |
Right - I struggled a bit with whether to deprecate |
I'm adding a developer message here - #3151 |
* refactor: useDrop ergonomics changes * spec.type is required * spec.item is optional, and may be an object or function. This replaces the spec.begin() function. * refactor: restore dropResult generic to useDrag * feat: improve DragSourceMonitor typings * feat: block beginDrag() in dnd-core if dragItem is nullish * chore: cut semver * fix: update getItem() type * fix: update native hooks examples * fix: some tests * fix: tests * fix: issue with dustbin stresstest * fix: liveness issue with monitor output * fix: liveness issue with monitor output * fix: minor test correction * fix: restore the ability to use spec.item with a type field and the begin() hook * fix: remove .begin from useDrag types * fix: update types * docs: change "ES6 Symbol" language to "symbol"
The
useDrag
hook has two modes of operation: building out return items withspec.item
and withspec.begin()
. When you usespec.begin()
, objects are expected to be of the type inspec.item.type
, which muddles concepts and can lead to some confusion. The deepest change here is separating the concerns of draggable type from draggable items.This change is a major semver change that refactors the
useDrag()
ergonomics.spec.type
is required. This should be the same value that was inspec.item.type
. This simplifies use cases that only use drag-types and no further drag-object details.spec.item
can be an object or function. The object does not need to contain thetype
property. The function may return an item object ornull
.null
cancels the drag operation. The function form ofitem
replacesbegin
, which is no longer present.end(item, result, monitor)
)The typings for monitors has been tightened. The interfaces for DragSourceMonitor and DropTargetMonitor now have type parameters for the DragObject and DropResult which default to unknown. Furthermore the getItem() and getResult() methods can be parameterized with the type expected (default is monitor typings).
Finally,
dnd-core
has been updated so that if a dragHandler returnsnull
orundefined
, the system will cancel the drag operation. This allows clients usinguseDrag({ item: () => condition ? null: validItem })
to cancel drag operations with client-side logic.Bugfixes include correcting liveness issues with hooks that were evident in the Dustbin stress test and fixing infinite render loops from shallowEqual being used when deepEqual is necessary.
Fixes #3110