cedricdelpoux / react-responsive-masonry

React responsive masonry component built with css flexbox
https://cedricdelpoux.github.io/react-responsive-masonry/
MIT License
372 stars 38 forks source link

Fix: Un even column items when Masonry child is invalid #109

Closed sarathjasrin closed 7 months ago

sarathjasrin commented 1 year ago

Hi @cedricdelpoux ,

When we render the Masonry child, sometimes we add an if condition to check if the element is valid.

const images = [
  "https://picsum.photos/200/300?image=1050",
  null,
  "https://picsum.photos/400/400?image=1039",
  null,
  "https://picsum.photos/400/400?image=1080",
]

<Masonry columnsCount={3} gutter="10px">
    {images.map((image, i) =>
      image ? (
        <img
          key={i}
          src={image}
          style={{width: "100%", display: "block"}}
        />
      ) : (
        ""
      )
    )}
  </Masonry>

In those cases, we may return unwanted empty or null children. This is causing uneven children inside the masonry getColumns function.

image

cedricdelpoux commented 7 months ago

Sorry for the delay 😞 It published in 2.2.0. Thank you for your help !