useDraggable - render only dragging item #1088
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
relates to #1071 only for active
in this PR we solve only the re-rendering for
useDraggable
hooks (and the components using it) when the active element changes.did not try to solve similar issues (yet) when
over
changes or foruseSortable
which exposesactiveIndex
andoverIndex
- to solve the issue there we will need to find a different API.Maybe something like over: 'item-before' | 'me' | 'item-after' | 'other' so that the whole list won't re-render while dragging.
I tried to make as little changes as possible, but there are still some pretty significant changes, including changes in the API:
useDraggable
now returnsnull
foractive
,activatorEvent
, andactiveNodeRect
if item isn't dragginguseDroppable
does not exposeactive
.please review and if you like the direction give some feedback.
if you like the direction I'll see if this PR needs some fine-tuning and start thinking about the same issue in other areas.
** I have added
use-sync-external-store
as a dependency. this is an official shim for the newuseSyncExternalStore
hook.It is possible to implement what I'm trying to achieve here without it, but it will result in a much harder-to-understand code and might cause issues with react 18 concurrent renderings.