Created
March 22, 2017 12:23
-
-
Save alextorn/8e5e05ce1b0dc055ea27e9b385b2fd6e to your computer and use it in GitHub Desktop.
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
// 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