Created
August 4, 2017 17:50
-
-
Save amankkg/21b81b730c2afb39aa2f4de9a7da7aa6 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
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