Skip to content

Instantly share code, notes, and snippets.

@choonkending
Last active September 5, 2016 00:15
Show Gist options
  • Save choonkending/e4bbb6ab2cb133e1c43c8b2791a877a1 to your computer and use it in GitHub Desktop.
Save choonkending/e4bbb6ab2cb133e1c43c8b2791a877a1 to your computer and use it in GitHub Desktop.
import React from 'react';
const showHide = (Title, Content) => class extends React.Component {
constructor(props) {
super(props);
this.state = { isActive: false };
this.onToggle = this.onToggle.bind(this);
}
render() {
return (
<div>
<Title onClick={onToggle} />
{ this.state.isActive && <Content /> }
</div>
);
}
onToggle() {
this.setState({ isActive: !this.state.isActive });
}
};
// Usage
const Title = props => <p {...props}>title</p>;
const Content = props => <p>content</p>;
const ConcreteToggle = showHide(Title, Content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment