brimdata / react-arborist

The complete tree view component for React
MIT License
3.03k stars 139 forks source link

Reorder with Tree.data set? #64

Open nickyvanurk opened 1 year ago

nickyvanurk commented 1 year ago

How does one drag/drop with the Tree.data attribute set (instead of the initialData). There are no drag and drop callbacks. Am I missing something? Also I would prefer to just use initialData, let the tree handle everything like it does by default, and have callbacks for when I add/edit/delete/drag nodes so I can update my database. Right now this isn't possible and I have to re-implement a lot of functionality in the callbacks because the callbacks don't work with initialData set.

ImADrafter commented 1 year ago

Hey! It is not official, since it is not on the documentation, but when I need a callback that happens to be exactly equal as what the library has implemented, what I do is the following:

CodeSandbox

BTW I encourage the maintainers of the library to confirm that this is cool. Maybe we can add this to the documentation ! :)

jameskerr commented 1 year ago

@ImADrafter this is a fine pattern to use. It's part of the public API even though it's not documented. Adding this to the documentation would be great! I'd welcome a PR.

The useSimpleTree hook is what is used under the hood when you pass "initialData".

@ImADrafter's code sandbox would probably work for you @nickyvanurk.