Last active
November 23, 2021 01:59
-
-
Save michelts/8fa36a30226a36eabb087b8dd9ff4677 to your computer and use it in GitHub Desktop.
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 FolderTree = ({folders}) => ( | |
<ul> | |
{folders.map(folder => ( | |
<Item key={folder.name} folder={folder} /> | |
))} | |
</ul> | |
); | |
const Item = ({folder}) => { | |
const [isOpen, setIsOpen] = useState(false); | |
return ( | |
<li> | |
<button type="button" onClick={() => setIsOpen((state) => !state)}> | |
{isOpen ? "-" : "+"} | |
</button>{" "} | |
{folder.name} | |
{isOpen && folder.contents?.length > 0 && ( | |
<FolderTree folders={folder.contents} /> | |
)} | |
</li> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment