Skip to content

Instantly share code, notes, and snippets.

@ovpv
Created March 23, 2019 10:04
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 ovpv/61d04df59eb82f5a2b7f5effaa95638e to your computer and use it in GitHub Desktop.
Save ovpv/61d04df59eb82f5a2b7f5effaa95638e to your computer and use it in GitHub Desktop.
accordion structure
class Accordion extends React.Component {
constructor(props) {
super(props)
this.state = {
tabs: [
{
id: 1,
title: "tab 1",
content: "this is tab 1",
active: true
},
{
id: 2,
title: "tab 2",
content: "this is tab 2",
active: false
},
{
id: 3,
title: "tab 3",
content: "this is tab 3",
active:false
}
]
}
}
render() {
const tabsArray = this.state.tabs;
return (
<div>
<h2>Accordion:</h2>
<div id="accordion">
{
tabsArray.map((tab,index)=>{
return <Tab key={index} id={tab.id} title={tab.title} content={tab.content} active={tab.active} />
})
}
</div>
</div>
)
}
}
ReactDOM.render(<Accordion />, document.querySelector("#app"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment