Skip to content

Instantly share code, notes, and snippets.

@jonathanharrell
Last active September 25, 2018 15:36
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 jonathanharrell/f8fa7c0cda6db5bf8c14b911f3038ecc to your computer and use it in GitHub Desktop.
Save jonathanharrell/f8fa7c0cda6db5bf8c14b911f3038ecc to your computer and use it in GitHub Desktop.
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