diff --git a/src/SwipeViews.js b/src/SwipeViews.js index 0fff829..2072fb2 100644 --- a/src/SwipeViews.js +++ b/src/SwipeViews.js @@ -11,7 +11,8 @@ export default class SwipeViews extends React.Component { constructor(props) { super(props); const selectedIndex = this.props.selectedIndex || 0; - const pageWidthPerCent = 100 / this.props.children.length; + const numChildren = React.Children.count(this.props.children) + const pageWidthPerCent = 100 / numChildren; const translation = selectedIndex * pageWidthPerCent; this.state = { selectedIndex, @@ -42,7 +43,7 @@ export default class SwipeViews extends React.Component { WebkitTransform: 'translateX(-' + this.state.translation + '%)', transitionProperty: this.state.animate ? 'all' : 'none', WebkitTransitionProperty: this.state.animate ? 'all' : 'none', - width: this.props.children.length * 100 + '%', + width: React.Children.count(this.props.children) * 100 + '%', }; return ( @@ -50,7 +51,7 @@ export default class SwipeViews extends React.Component {