Last active
February 25, 2019 16:53
-
-
Save Nitemaeric/3f1e18cc73101a9495a6982a691caa40 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
import React from 'react' | |
import PropTypes from 'prop-types' | |
class ConditionalComponent extends React.Component { | |
static propTypes = { | |
title: PropTypes.string, | |
hidden: PropTypes.bool, | |
expanded: PropTypes.bool, | |
onClick: PropTypes.func | |
} | |
render () { | |
if (!this.props.hidden) { | |
return ( | |
<div> | |
<h1>Here is the {this.props.title}</h1> | |
{ | |
this.props.expanded && ( | |
<div> | |
<p>Here is an extended description of something</p> | |
<button onClick={this.props.onClick}>Do Something</button> | |
</div> | |
) | |
} | |
</div> | |
) | |
} | |
else { | |
return null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment