Last active
August 29, 2015 14:20
-
-
Save alexkirsz/ec9f5d4479efc115e533 to your computer and use it in GitHub Desktop.
Children propType validation
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
let propTypes = { | |
children(props, propName) { | |
let errors = []; | |
React.Children.map(props[propName], child => { | |
if (child.type !== Foo) { | |
errors.push(`${child.key} is not a Foo element`); | |
} | |
}); | |
if (errors.length > 0) { | |
return new Error(errors.join(', ')); | |
} | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment