Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Accordion Item Component Using Context
class AccordionItem extends React.Component {
constructor (props) {
super(props)
this.toggleExpansion = () => {
this.setState({ expanded: !this.state.expanded })
}
this.state = {
expanded: false,
toggleExpansion: this.toggleExpansion
}
}
render () {
return (
<AccordionItemContext.Provider value={this.state}>
<div className="accordion-item">
{this.props.children}
</div>
</AccordionItemContext.Provider>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.