@@ -243,7 +243,8 @@ class Carousel extends React.Component {
243243 /* based on slider container's width, get num of items to show
244244 * and calculate child's width (and update it in state)
245245 */
246- const childrenLength = Children . toArray ( children ) . length ;
246+ const childrenLength = Children . toArray ( children ) . length || 1 ;
247+
247248 let childWidth = 0 ;
248249 if ( verticalMode ) {
249250 childWidth = sliderContainerWidth ;
@@ -284,7 +285,7 @@ class Carousel extends React.Component {
284285 children
285286 } = this . getDerivedPropsFromBreakPoint ( ) ;
286287
287- const childrenLength = Children . toArray ( children ) . length ;
288+ const childrenLength = Children . toArray ( children ) . length || 1 ;
288289
289290 this . setState (
290291 currentState => {
@@ -345,7 +346,7 @@ class Carousel extends React.Component {
345346 itemsToShow,
346347 itemsToScroll
347348 } = this . getDerivedPropsFromBreakPoint ( ) ;
348- const childrenLength = Children . toArray ( children ) . length ;
349+ const childrenLength = Children . toArray ( children ) . length || 1 ;
349350 const notEnoughItemsToShow = itemsToShow > childrenLength ;
350351 let limit = getPrev ? 0 : childrenLength - itemsToShow ;
351352
@@ -393,7 +394,7 @@ class Carousel extends React.Component {
393394 const childWidth = this . calculateChildWidth ( ) ;
394395
395396 // determine how far can user swipe
396- const childrenLength = Children . toArray ( children ) . length ;
397+ const childrenLength = Children . toArray ( children ) . length || 1 ;
397398 const goingNext =
398399 ( ! verticalMode && dir === "Left" && ! isRTL ) ||
399400 ( ! verticalMode && dir === "Right" && isRTL ) ||
0 commit comments