Skip to content

Instantly share code, notes, and snippets.

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