How ResponsiveMasonry and Masonry work together
masterTo create a masonry layout where the number of columns and the gutter size change based on the window size, you must wrap the Masonry component with the ResponsiveMasonry component.
If you want a static layout where the column count remains constant regardless of screen size, use the Masonry component alone.
Responsive Layout Example
import React from "react"
import Masonry, {ResponsiveMasonry} from "react-responsive-masonry"
const MyWrapper = () => (
<ResponsiveMasonry
columnsCountBreakPoints={{350: 1, 750: 2, 900: 3}}
gutterBreakPoints={{350: "12px", 750: "16px", 900: "24px"}}
>
<Masonry>
<ChildA />
<ChildB />
<ChildY />
<ChildZ />
</Masonry>
</ResponsiveMasonry>
)Static Layout Example
import React from "react"
import Masonry from "react-responsive-masonry"
const MyWrapper = () => (
<Masonry columnsCount={3}>
<ChildA />
<ChildB />
<ChildY />
<ChildZ />
</Masonry>
)import React from "react"
import Masonry, {ResponsiveMasonry} from "react-responsive-masonry"
// The number of columns and the gutter change by resizing the window
class MyWrapper extends React.Component {
render() {
return (
<ResponsiveMasonry
columnsCountBreakPoints={{350: 1, 750: 2, 900: 3}}
gutterBreakPoints={{350: "12px", 750: "16px", 900: "24px"}}
>
<Masonry>
<ChildA />
<ChildB />
{/* Children */}
<ChildY />
<ChildZ />
</Masonry>
</ResponsiveMasonry>
)
}
}
// The number of columns and the gutter don't change by resizing the window
class MyWrapper extends Component {
render() {
return (
<Masonry columnsCount={3}>
<ChildA />
<ChildB />
{/* Children */}
<ChildY />
<ChildZ />
</Masonry>
)
}
}