chenglou / react-motion

A spring that solves your animation problems.
MIT License
21.7k stars 1.16k forks source link

Duplicated elements when using Motion component #583

Open abohannon opened 4 years ago

abohannon commented 4 years ago

We're using Motion in an image slider and all slides are duplicated when changing slides. Here's a screenshot after interacting with the slider a few times. The slider starts with 5 slides wrapped in Motion components.

Screen Shot 2019-12-30 at 11 35 53 AM

Here's the implementation:

{items.map(
          ({ image, content, style, defaultStyle, imageClass }, index) => (
            <Motion
              key={image}
              defaultStyle={getDefaultStyle(index)}
              style={style}
            >
              {style => {
                return (
                  <div
                    style={{
                      transform: `translateX(${style.x}vw)`,
                      height: slideHeight,
                      maxHeight: slideHeight,
                    }}
                    className={classNames(
                      'carouselSlide',
                      classes.carouselSlide,
                    )}
                  >
                    <img
                      alt={image}
                      src={image}
                      className={classNames(imageClass, classes.image)}
                    />
                  </div>
                )
              }}
            </Motion>
          ),
        )}
nkbt commented 4 years ago

console.log(items)

There is smth to do with how you change items. Motion does nothing to duplicate elements