Help creating a custom tree data provider #252
-
Hi there. I'm quite new to using react, and especially typescript. I've been working (and learning while doing so) on a project that requires the eventual implementation of an interactive and dynamic 'item tree' and this package seemed really promising for that. The biggest issue I have is that the data I'm using (and receiving from my API) does not work with or translate well to the StaticTreeDataProvider that is used for getting started. I've concluded that making a custom data provider would seem to be the best solution, but I have near to no experience creating something like this. The basic structure of the data I receive from my API is something like this:
Where Basically I want the generated tree to consist of each item in the array, where the entry name is the The main thing I'm struggling with here is the lack of examples for Big thanks if someone can help or give pointers here. Examples would be hugely appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I would like to see documentation around a basic example of this as well. |
Beta Was this translation helpful? Give feedback.
-
Edit: I expanded the docs on static data providers and on custom data providers, which right now is the best entry point with details on how to approach this. A simple example is actually the implementation of the The gist is to implement a I agree that some proper examples would benefit the current docs. I don't have the time to add some at the moment, but I'll create an issue from this discussion to keep track of this. |
Beta Was this translation helpful? Give feedback.
Edit: I expanded the docs on static data providers and on custom data providers, which right now is the best entry point with details on how to approach this.
A simple example is actually the implementation of the
StaticTreeDataProvider
itself, it implements all methods of a tree data provider, and with 50 LOC it's pretty manageable to understand: https://github.com/lukasbach/react-complex-tree/blob/main/packages/core/src/uncontrolledEnvironment/StaticTreeDataProvider.tsThe gist is to implement a
getTreeItem(itemId: string | number): Promise<Item>
method that allows RCT to retrieve item data for item IDs. All other methods are pretty much additional features. If you expect your items to …