Last active
March 15, 2016 09:46
-
-
Save nnarhinen/c062d2ffa68c50948292 to your computer and use it in GitHub Desktop.
OR validation for React props
This file contains hidden or 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 Component = React.createClass({ | |
propTypes: { | |
file: requireThisOr('files', React.PropTypes.instanceOf(File).isRequired), | |
files: requireThisOr('file', React.PropTypes.arrayOf(React.PropTypes.instanceOf(File)).isRequired) | |
} | |
}) |
This file contains hidden or 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
export default function requireThisOr(otherProp, propValidator) { | |
return (props, propName, componentName) => { | |
if (!props[otherProp]) { | |
return propValidator(props, propName, componentName); | |
} | |
}; | |
} |
Author
nnarhinen
commented
Mar 15, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment