diff --git a/src/components/Card/Card.js b/src/components/Card/Card.js index 9991bdd..4086e89 100644 --- a/src/components/Card/Card.js +++ b/src/components/Card/Card.js @@ -106,8 +106,9 @@ class Card extends React.Component { const siblings = React.Children.map( children, child => - /* $FlowFixMe */ - typeof child === 'object' && child.type ? child.type.displayName : null + React.isValidElement(child) && child.type + ? child.type.displayName + : null ); return ( { {React.Children.map( children, (child, index) => - typeof child === 'object' && child !== null - ? /* $FlowFixMe */ - React.cloneElement(child, { + React.isValidElement(child) + ? React.cloneElement(child, { index, total, siblings, diff --git a/src/components/Card/CardActions.js b/src/components/Card/CardActions.js index 97ed00c..6f79bab 100644 --- a/src/components/Card/CardActions.js +++ b/src/components/Card/CardActions.js @@ -36,10 +36,8 @@ class CardActions extends React.Component { {React.Children.map( this.props.children, child => - typeof child === 'object' && child !== null - ? /* $FlowFixMe */ - React.cloneElement(child, { - /* $FlowFixMe */ + React.isValidElement(child) + ? React.cloneElement(child, { compact: child.props.compact !== false, }) : child diff --git a/src/components/Dialog/Dialog.js b/src/components/Dialog/Dialog.js index 61babc6..c15a929 100644 --- a/src/components/Dialog/Dialog.js +++ b/src/components/Dialog/Dialog.js @@ -101,24 +101,28 @@ class Dialog extends React.Component { const backgroundColor = theme.colors.paper; const childrenArray = React.Children.toArray(children); - /* $FlowFixMe */ - const title = childrenArray.find(child => child.type === DialogTitle); + const title = childrenArray.find( + child => React.isValidElement(child) && child.type === DialogTitle + ); const actionBtnsChildren = childrenArray.filter( - /* $FlowFixMe */ - child => child && child.type === DialogActions + child => React.isValidElement(child) && child.type === DialogActions ); const restOfChildren = childrenArray.filter( child => - /* $FlowFixMe */ - child && child.type !== DialogActions && child.type !== DialogTitle + React.isValidElement(child) && + child.type !== DialogActions && + child.type !== DialogTitle ); let restOfChildrenWithoutTitle = restOfChildren; if (!title) { let found = false; restOfChildrenWithoutTitle = restOfChildren.map(child => { - if (child.type === DialogContent && !found) { + if ( + React.isValidElement(child) && + child.type === DialogContent && + !found + ) { found = true; - /* $FlowFixMe */ return React.cloneElement(child, { style: { paddingTop: 24 }, }); diff --git a/src/components/Dialog/DialogActions.js b/src/components/Dialog/DialogActions.js index 2dab130..0d6eced 100644 --- a/src/components/Dialog/DialogActions.js +++ b/src/components/Dialog/DialogActions.js @@ -46,9 +46,8 @@ const DialogActions = (props: Props) => ( {React.Children.map( props.children, child => - typeof child === 'object' && child !== null - ? /* $FlowFixMe */ - React.cloneElement(child, { + React.isValidElement(child) + ? React.cloneElement(child, { compact: true, }) : child diff --git a/src/components/List/ListAccordion.js b/src/components/List/ListAccordion.js index bce7e7d..a9d82fa 100644 --- a/src/components/List/ListAccordion.js +++ b/src/components/List/ListAccordion.js @@ -154,7 +154,12 @@ class ListAccordion extends React.Component { {this.state.expanded ? React.Children.map(children, child => { - if (icon && child && !child.props.icon && !child.props.avatar) { + if ( + icon && + React.isValidElement(child) && + !child.props.icon && + !child.props.avatar + ) { return React.cloneElement(child, { style: [styles.child, child.props.style], }); diff --git a/src/components/Toolbar/Toolbar.js b/src/components/Toolbar/Toolbar.js index 5d9b880..cce8e18 100644 --- a/src/components/Toolbar/Toolbar.js +++ b/src/components/Toolbar/Toolbar.js @@ -137,9 +137,16 @@ class Toolbar extends React.Component { if (Platform.OS === 'ios') { childrenArray.forEach(child => { - if (!isToolbarContentFound && child.type !== ToolbarContent) { + if ( + !isToolbarContentFound && + React.isValidElement(child) && + child.type !== ToolbarContent + ) { leftActions++; - } else if (child.type === ToolbarContent) { + } else if ( + React.isValidElement(child) && + child.type === ToolbarContent + ) { isToolbarContentFound = true; } else { rightActions++; @@ -172,25 +179,27 @@ class Toolbar extends React.Component { {...rest} > - {childrenArray.filter(Boolean).map((child: any, i) => { - const props: { dark: ?boolean, style?: any } = { - dark: - typeof child.props.dark === 'undefined' - ? isDark - : child.props.dark, - }; + {childrenArray + .filter(child => React.isValidElement(child)) + .map((child: any, i) => { + const props: { dark: ?boolean, style?: any } = { + dark: + typeof child.props.dark === 'undefined' + ? isDark + : child.props.dark, + }; - if (child.type === ToolbarContent) { - // Extra margin between left icon and ToolbarContent - props.style = [ - { marginHorizontal: i === 0 ? 0 : 8 }, - centerIos && { alignItems: 'center' }, - child.props.style, - ]; - } + if (child.type === ToolbarContent) { + // Extra margin between left icon and ToolbarContent + props.style = [ + { marginHorizontal: i === 0 ? 0 : 8 }, + centerIos && { alignItems: 'center' }, + child.props.style, + ]; + } - return React.cloneElement(child, props); - })} + return React.cloneElement(child, props); + })} );