Skip to content

The package does not work with a single image #27

Closed
@javier-mora

Description

@javier-mora

The package does not work when there is only one element in the array.

I know the package is designed for more than one image, but when retrieving images from an API via filters, many times you don't have control of how many images will be returned.

Here is the code for this:

<SimpleImageSlider
                    width={"500px"}
                    height={"500px"}
                    images={[
                        {url: "/images/img1.png"},
                    ]}
                    showNavs={true}
                    showBullets={false}                    
                />

Error:

TypeError: Cannot read property 'url' of undefined
SimpleImageSlider
/node_modules/react-simple-image-slider/dist/index.js:237
  234 |     currentSliderStyle = _React$useState8[0],
  235 |     setCurrentSlideStyle = _React$useState8[1];
  236 | 
> 237 | var _React$useState9 = React.useState(styles.getImageSlide(images[1].url, slideDuration, 1, useGPURender)),
      | ^  238 |     _React$useState10 = _slicedToArray(_React$useState9, 2),
  239 |     nextSliderStyle = _React$useState10[0],
  240 |     setNextSliderStyle = _React$useState10[1];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions