Last active
September 25, 2018 15:36
-
-
Save jonathanharrell/f8fa7c0cda6db5bf8c14b911f3038ecc to your computer and use it in GitHub Desktop.
Accordion Item Component Using Context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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