Created
February 24, 2019 23:20
-
-
Save merlos/1226c47739026b93e2ed6cb6a822994b 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
# Import the tree component | |
import {Tree} from 'untree-react' | |
class MyComponent extends React.Component { | |
constructor() { | |
//initialize the Tree | |
this.state.tree = { | |
name: "Node 1" | |
children: [ | |
{name: "Node 1.1"} | |
{name: "Node 1.2"} | |
] | |
} | |
} | |
//handle click | |
handleClick(node) { | |
console.log(node) | |
} | |
//handle expand | |
handleExpandToggle(node) { | |
this.setState({tree: this.state.tree.expandToggle(node)}) | |
} | |
//... | |
render() { | |
return( | |
<Tree | |
tree={this.state.tree} | |
onClick={(node) => handleClick(node)} | |
onExpandToggle ={(node) => handleExpandToggle(node)} /> | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment