React-sortable-tree: Max Depth

Created on 16 May 2018  路  4Comments  路  Source: frontend-collective/react-sortable-tree

Is there a function to get the max depth of the tree?

question

Most helpful comment

That did it thanks!
For anyone wondering, this is what I did:

            let depth = 0;
            walk({
                treeData: treeData,
                getNodeKey,
                callback: (node) => {
                    if(node.path.length > depth) depth= node.path.length; 
                },
            });

All 4 comments

I would use walk and in the callback check the length of the path array which is essentially the depth of the node in the tree.

https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L326

hope that helps!

That did it thanks!
For anyone wondering, this is what I did:

            let depth = 0;
            walk({
                treeData: treeData,
                getNodeKey,
                callback: (node) => {
                    if(node.path.length > depth) depth= node.path.length; 
                },
            });

@anushkadoyan, cool example, maybe we can create a storybook example so other people don't have the same pains... I will try to update it sometime this week...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vladimirsvsv77 picture vladimirsvsv77  路  5Comments

29er picture 29er  路  5Comments

xmhscratch picture xmhscratch  路  5Comments

vaheqelyan picture vaheqelyan  路  4Comments

bigjujube picture bigjujube  路  4Comments