cedricdelpoux / react-responsive-masonry

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

Making single child centered? #45

Closed TheSayantan96 closed 2 years ago

TheSayantan96 commented 3 years ago

Is there a way we can make a single child horizontally center aligned?

keegandonley commented 3 years ago

FWIW I had a similar use case and came here to search first, but was able to accomplish it on my own by pre-calculating how many children I would have:

<ResponsiveMasonry columnsCountBreakPoints={children.length === 1 ? { 0: 1 } : { 1023: 1, 1024: 2 }}>
    <Masonry columnsCount={children.length === 1 ? 1 : undefined}>
        {...children}
    </Masonry>
</ResponsiveMasonry>

Not sure if this is the best/only approach but it works well for me

cedricdelpoux commented 2 years ago

This is the best approach for now. Thanks @keegandonley