Skip to content

Instantly share code, notes, and snippets.

@merlos
Created February 24, 2019 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merlos/1226c47739026b93e2ed6cb6a822994b to your computer and use it in GitHub Desktop.
Save merlos/1226c47739026b93e2ed6cb6a822994b to your computer and use it in GitHub Desktop.
# 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