tree icon indicating copy to clipboard operation
tree copied to clipboard

Deprecation of `children` and more complex Trees

Open gabrieldutra opened this issue 1 year ago • 1 comments

Hey there! First let me know if this is not the right place for discussions like this, I'm happy to move it elsewhere if so :)

Recently I've been working with a large Tree and with treeData I can think about two main ways of structuring it: 1. A memoized object derived from your tree dependencies; or 2. A Tree state / reducer with the triggers to update it (main case in docs). The problem I see/I'm facing with it is that it translates into a linear structure (coming from React / how hooks work), being transformed into a Tree:

function Component() {
  const firstLevelData = useGetFirstLevelData(); // even more of a problem when these are async
  const secondLevelData = useGetSecondLevelData();
  // + any other dep to build the tree
  const treeData = /* build tree, with everything needed inside this component */;
  return <Tree treeData={treeData} />;
}

This got me thinking: the DOM itself is a Tree, so having it performant and with good ways to abstract it is part of the problem React had to solve, which makes React nodes potentially the best way of solving this:

function SecondLevelNode() {
  const thirdLevelData = useGetThirdLevelData();
  return <TreeNode />; // + any other Node component, can even be <LoadingNode /> when async for example
}

function FirstLevelNode() {
  const secondLevelData = useGetSecondLevelData();
  return <TreeNode>{secondLevelData.map(() => <SecondLevelNode />)}</TreeNode>
}

function Component() {
  const firstLevelData = useGetFirstLevelData();
  return <Tree>{firstLevelData.map(() => <FirstLevelNode />)}</Tree>
}

I know there's a deprecation note in https://github.com/react-component/tree/blob/7dbaebb3fa3ddead8b0a24284169a12133ca074e/src/Tree.tsx#L367 for the children prop (also it's not used in any example), which was added with #261. However virtualization seemed to still work when using it. So I'm wondering:

  1. Is there any limitation/issue for it to be deprecated?
  2. Does it make sense to keep supporting it for better structuring Trees with different dependencies for each level?

Thanks!!

gabrieldutra avatar Mar 23 '23 02:03 gabrieldutra

Now I have to manage node styles at the data level (treeData prop)?

ivanov-v avatar Aug 28 '23 10:08 ivanov-v