-
Notifications
You must be signed in to change notification settings - Fork 128
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
Added useDynamicTree hook #172
base: main
Are you sure you want to change the base?
Conversation
The useSimpleTree hook only allows initial data and there is no method to allow changing that data. With this new hook useDynamicTree we can change the tree data dynamics for example: In a ReactJs or NextJS project we can make an api call then set the data to be use for the tree and there is no need to write the controller functions. Basically this hooks works just like the useSimpleTree hook except you change change or load the data when needed. ```const { data, setData, controllers } = useDynamicTree()``` There is no need to pass in initialData and you can set the data using the setData function.
Hi @jerryseigle I appreciate your PR. Thank you for the time. I am seeing the need from you and others for a simpler interface to the tree, but I'm not certain this is it. I'll take some time to consider what the API should be going forward. This is a good idea though and I expect to take inspiration from it. In the meantime, users can use your PR as an example of creating their own controllers for the tree. |
@jameskerr sounds great. Do you have an estimated ETA when you will be releasing new API. |
I do not have an ETA. But I like working on the project and enjoy spending some of my free time making it better. |
@jerryseigle thanks for that hook, this is exactly what I needed. I think this hook is what you need to add or just export setData on useSimpleTree and it take not only initialData but update data as well. BTW, I am trying to store tree structure in sqlite and I do have order for items (indexes in your component) but in order to get UI and backend in sync, I need to send the those leafs items order back to db. No sure if there is a better way to store a tree in SQL table. Thanks for great component, pleasure use it, well designed. |
I added a hook that supports dynamic data.
Currently there is a hook called useSimpleTree which keeps everything simple. It manages the tree data and provides all of the controller functions such as onCreate, onRename, onUpdate, onDelete. This makes it easy to use the tree however you have to provide initial data
I added a hook called useDynamicTree which works exactly like the simpleTree hook example it provides an option to allow us to set the data that will be used in the tree whenever we need to set it. Of course we can already use dynamic data simply by using the data prop provided in the Tree component. But what makes this hook needed is that it keeps everything simple for some of us that need to keep things simple. It provides all of the functions just like useSimpleTree. As you may know that when using the data prop in the tree we have to add the controller functions manually. With this hook you do not need to do that. Again it makes things simple.
Usage Example: