Skip to content

Instantly share code, notes, and snippets.

@amankkg
Created August 4, 2017 17:50
Show Gist options
  • Save amankkg/21b81b730c2afb39aa2f4de9a7da7aa6 to your computer and use it in GitHub Desktop.
Save amankkg/21b81b730c2afb39aa2f4de9a7da7aa6 to your computer and use it in GitHub Desktop.
const trickyPropType = getPropTypeFromProps =>
(props, propName, componentName) => {
const error = getPropTypeFromProps(props)(props, propName, componentName)
if (error) return error // WIP
}
const Summary = ({ hasErrors, errors }) =>
<div>
{hasErrors &&
errors.map(err => <span key={err}>{err}</span>)}
</div>
Summary.propTypes = {
hasErrors: bool.isRequired,
errors: trickyPropType(
props => props.hasErrors
? arrayOf(string).isRequired
: arrayOf(string),
),
}
Summary.defaultProps = {
errors: [],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment