Skip to content
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

useDraggable - render only dragging item #1088

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

alissaVrk
Copy link

@alissaVrk alissaVrk commented Mar 30, 2023

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 for useSortable which exposes activeIndex and overIndex - 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 returns null for active, activatorEvent, and activeNodeRect if item isn't dragging
  • useDroppable does not expose active.

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 new useSyncExternalStore 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.

@changeset-bot
Copy link

changeset-bot bot commented Mar 30, 2023

⚠️ No Changeset found

Latest commit: d2d5043

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

Successfully merging this pull request may close these issues.

1 participant