-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
[next] controlled or cancellable useSortable #1434
Comments
There's a few ways you can do this: If you want to completely disable optimistic re-ordering of items, you can call import {DragDropProvider} from '@dnd-kit/react';
function App() {
return (
<DragDropProvider onDragOver={(event) => event.preventDefault()}>
...
</DragDropProvider>
)
} You can also manage the state of your items in React, and update it in import {useState} from 'react';
import {DragDropProvider} from '@dnd-kit/react';
import {move} from '@dnd-kit/helpers';
function App() {
const [items, setItems] = useState(['A', 'B', 'C', 'D']);
return (
<DragDropProvider
onDragOver={(event) => {
const {dragOperation: {source, target}} = event;
setItems((items) => move(items, source, target));
}}
>
{items.map((item, index) => <Sortable key={item} id={item} index={index} />
</DragDropProvider>
)
} When you update the items in React in the |
I don't know if you have seen but there's a new documentation website where you can learn more: https://next.dndkit.com Not everything is documented yet, but this guide can be helpful: https://next.dndkit.com/react/guides/multiple-sortable-lists |
Thank you, the documentation helped 👍. This seems to be the best library for drag and drop in react. A couple more questions about the new version:
Thanks. |
At the moment I'm not considering introducing strategies for The new library works a bit differently from the previous one when it comes to The new library moves the element you connect to useSortable({id, feedback: 'clone'}); The clone has the const {ref, isDragSource} = useSortable({id});
return (
<button style={{background: isDragSource ? 'green' : 'red'} ref={ref}>Drag me</button>
) |
Thank you. data-dnd-placeholder works great. |
Hi.
I'm trying to upgrade to a new version of DND-KIT, but I'm running into a problem with compatibility.
I'm using the useSortable hook to move cards (change their order).
A problem arises that cards save new positions immediately after moving (optimistic rendring) and this cannot be canceled in any way in the onDragEnd attribute, or return to previous positions. Is there such a possibility?
The point is that I need to send the new order of cards to the server and handle possible responce errors.
May be Is it possible to programmatically cancel the movement? or make the order of elements controlled externally? (for example, change the order programmatically from store).
Thanks!
The text was updated successfully, but these errors were encountered: