Skip to content

Instantly share code, notes, and snippets.

@grantsheppard
Created April 6, 2017 04:09
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 grantsheppard/9404c96f13f8761a228c9cc86b31ca67 to your computer and use it in GitHub Desktop.
Save grantsheppard/9404c96f13f8761a228c9cc86b31ca67 to your computer and use it in GitHub Desktop.
class Tabs extends React.Component {
static propTypes = {
data: React.PropTypes.array.isRequired
}
state = {
activeTabIndex: 0
}
handleTabClick(activeTabIndex) {
this.setState({ activeTabIndex })
}
renderTabs() {
return this.props.data.map((tab, index) => {
return (
<div onClick={() => this.handleTabClick(index)}>{tab.name}</div>
)
})
}
renderPanel() {
const tab = this.props.data[this.state.activeTabIndex]
return (
<div><p>{tab.description}</p></div>
)
}
render() {
return (
<div>
<div>
{this.renderTabs()}
</div>
<div>
{this.renderPanel()}
</div>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment