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

Update UniqueIdentifier interface to allow number ids #755

Merged
merged 1 commit into from
May 21, 2022

Conversation

clauderic
Copy link
Owner

The UniqueIdentifier type has been updated to now accept either string or number identifiers. As a result, the id property of useDraggable, useDroppable and useSortable and the items prop of <SortableContext> now all accept either string or number identifiers.

Migration steps

For consumers that are using TypeScript, import the UniqueIdentifier type to have strongly typed local state:

+ import type {UniqueIdentifier} from '@dnd-kit/core';

function MyComponent() {
-  const [items, setItems] = useState(['A', 'B', 'C']);
+  const [items, setItems] = useState<UniqueIdentifier>(['A', 'B', 'C']);
}

Alternatively, consumers can cast or convert the id property to a string when reading the id property of interfaces such as Active, Over, DroppableContainer and DraggableNode.

The draggableNodes object has also been converted to a map. Consumers that were reading from the draggableNodes property that is available on the public context of <DndContext> should follow these migration steps:

- draggableNodes[someId];
+ draggableNodes.get(someId);

@changeset-bot
Copy link

changeset-bot bot commented May 20, 2022

🦋 Changeset detected

Latest commit: da1337a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@dnd-kit/core Major
@dnd-kit/sortable Major
@dnd-kit/modifiers Major

Not sure what this means? Click here to learn what changesets are.

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

@clauderic clauderic force-pushed the number-unique-identifier branch 2 times, most recently from f636271 to 984204f Compare May 20, 2022 21:15
@clauderic clauderic merged commit 33e6dd2 into master May 21, 2022
@clauderic clauderic deleted the number-unique-identifier branch May 21, 2022 01:12
@github-actions github-actions bot mentioned this pull request May 21, 2022
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.

None yet

1 participant