6 ms·
I'm very excited about: React.Children.map now returns plain arrays too Before this change, we would have to do the following when checking the types of c
by nickpresta 11y ago
I'm very excited about:
React.Children.map now returns plain arrays too
Before this change, we would have to do the following when checking the types of children components (in propType validation):
const childrenTypes = [];
React.Children.forEach(props.children, child => {
childrenTypes.push(child.type);
});
for (const type of childrenTypes) {
if (type !== MyComponent) {
return new Error(`Child '${type}' is not an instance MyComponent. Check render method of 'ParentComponent'.`);
}
}
It sort of made sense that map() on an opaque data structure would return the same type of data structure but in practice this was rarely useful.
Thanks, React team!
- seivan 11y agoThis also helps with Typescript that required var products:Array<Product> = [] for (var x in this.props.products) { products.push(this.props.products[x]) }