Skip to content

Instantly share code, notes, and snippets.

@alexkirsz
Last active August 29, 2015 14:20
Show Gist options
  • Save alexkirsz/ec9f5d4479efc115e533 to your computer and use it in GitHub Desktop.
Save alexkirsz/ec9f5d4479efc115e533 to your computer and use it in GitHub Desktop.
Children propType validation
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