Last active
January 20, 2019 16:58
-
-
Save DmitryMarkov/c3d085a847c89da91fbc9341fe179c95 to your computer and use it in GitHub Desktop.
TreeComponent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TreeComponent = ({ folders, children }) => { | |
const renderTree = (folders, level = 0) => | |
folders.length && folders.map(folder => { | |
if (folder.children && folder.children.length) { | |
return [ | |
children({ folder, level }), | |
...renderTree(folder.children, level + 1) | |
] | |
} | |
return children({ folder, level }) | |
}) | |
return renderTree(folders) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment