Skip to content

Instantly share code, notes, and snippets.

@Nitemaeric
Last active February 25, 2019 16:53
Show Gist options
  • Save Nitemaeric/3f1e18cc73101a9495a6982a691caa40 to your computer and use it in GitHub Desktop.
Save Nitemaeric/3f1e18cc73101a9495a6982a691caa40 to your computer and use it in GitHub Desktop.
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