Skip to content

Instantly share code, notes, and snippets.

@alextorn
Created March 22, 2017 12:23
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 alextorn/8e5e05ce1b0dc055ea27e9b385b2fd6e to your computer and use it in GitHub Desktop.
Save alextorn/8e5e05ce1b0dc055ea27e9b385b2fd6e to your computer and use it in GitHub Desktop.
// Children component, handleClick in props
const BodyOverlay = ({ handleClick }) => (
<div className="body_overlay" onClick={handleClick} />
);
// propType checking
BodyOverlay.propTypes = {
handleClick: PropTypes.func.isRequired
};
// Parent component
class App extends Component {
state = {
isMenuOpen: false
}
// set function
handleClick = () => {
this.setState({
isMenuOpen: !this.state.isMenuOpen
});
}
render() {
return (
<div className="layout" >
<BodyOverlay handleClick={this.handleClick} />
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment