Skip to content

Deprecation of children and more complex Trees #734

Open
@gabrieldutra

Description

@gabrieldutra

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

warning(false, '`children` of Tree is deprecated. Please use `treeData` instead.');
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!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions