
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
masonry-grid-component
Advanced tools
A Pinterest-style grid layout component built on top of @zapperwing/pinterest-view
Pinterest-style grid layout component that automatically arranges child elements in an optimized grid pattern. Built on top of @zapperwing/pinterest-view, this component provides virtualization support for grids with a large number of cards.
npm install masonry-grid-component
This component is built on top of @zapperwing/pinterest-view v2.0.0+ and includes support for:
import { MasonryGrid } from 'masonry-grid-component';
function Gallery() {
return (
<MasonryGrid columnWidth={300} gutter={15}>
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</MasonryGrid>
);
}
<MasonryGrid columnWidth="33.33%" gutter={15}>
{/* items */}
</MasonryGrid>
<MasonryGrid
columnWidth={300}
gutter={15}
monitorImagesLoaded={true}
>
<img src="image1.jpg" />
<img src="image2.jpg" />
</MasonryGrid>
import { MasonryGrid, MasonryGridRef } from 'masonry-grid-component';
import { useRef } from 'react';
function DynamicGallery() {
const gridRef = useRef<MasonryGridRef>(null);
const handleContentChange = () => {
gridRef.current?.updateLayout();
};
return (
<MasonryGrid ref={gridRef} columnWidth={300} gutter={15}>
{/* Dynamic content */}
</MasonryGrid>
);
}
import { MasonryGrid, MasonryGridRef } from 'masonry-grid-component';
import { useRef } from 'react';
function GalleryWithFreeze() {
const gridRef = useRef<MasonryGridRef>(null);
const handleFreeze = () => {
gridRef.current?.freeze(); // Locks current layout
};
const handleUnfreeze = () => {
gridRef.current?.unfreeze(); // Allows normal reflow
};
return (
<div>
<button onClick={handleFreeze}>Freeze Layout</button>
<button onClick={handleUnfreeze}>Unfreeze Layout</button>
<MasonryGrid ref={gridRef} columnWidth={300} gutter={15}>
{/* Grid items */}
</MasonryGrid>
</div>
);
}
import { MasonryGrid } from 'masonry-grid-component';
import { useRef } from 'react';
function ScrollableGallery() {
const scrollContainerRef = useRef<HTMLDivElement>(null);
return (
<div
ref={scrollContainerRef}
style={{ height: '600px', overflow: 'auto' }}
>
<MasonryGrid
columnWidth={300}
gutter={15}
virtualized={true}
scrollContainer={scrollContainerRef.current}
>
{/* Grid items */}
</MasonryGrid>
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
columnWidth | number | string | 150 | Width of each column. Can be pixels or percentage |
gutter | number | 5 | Spacing between items in pixels |
monitorImagesLoaded | boolean | false | Whether to monitor and reflow when images load |
onLayout | (layout: { height: number }) => void | - | Callback function when layout changes |
className | string | - | Additional CSS class for the grid container |
style | React.CSSProperties | - | Additional inline styles |
id | string | - | Unique identifier for the component |
children | ReactNode | - | Grid items to be rendered |
virtualized | boolean | false | Enable virtualization for better performance with large lists |
virtualizationBuffer | number | 800 | Buffer size for virtualization in pixels |
debug | boolean | false | Enable debug logging |
rtl | boolean | false | Enable right-to-left layout |
scrollContainer | HTMLElement | - | Custom scroll container for virtualization (defaults to window) |
When using a ref with the MasonryGrid component, you can access these methods:
| Method | Description |
|---|---|
updateLayout() | Manually triggers a layout recalculation |
clearCache() | Clears the height cache and triggers a layout update |
freeze() | Freezes the current layout in place (locks positions) |
unfreeze() | Clears the frozen state so new items will re-flow normally |
forwardRef for ref forwarding@zapperwing/pinterest-viewThe component uses virtualized rendering through the StackGrid component, making it efficient even with thousands of items:
<StackGrid
virtualized={true}
columnWidth={columnWidth}
gutterWidth={gutter}
gutterHeight={gutter}
>
{children}
</StackGrid>
Exposes an imperative handle for manual layout updates and layout freezing:
useImperativeHandle(ref, () => ({
updateLayout: () => {
if (gridRef.current?.updateLayout) {
gridRef.current.updateLayout();
} else if (gridRef.current?.layout) {
gridRef.current.layout();
}
},
clearCache: () => {
// Trigger a layout update as a fallback
if (gridRef.current?.updateLayout) {
gridRef.current.updateLayout();
} else if (gridRef.current?.layout) {
gridRef.current.layout();
}
},
freeze: () => {
if (gridRef.current?.freeze) {
gridRef.current.freeze();
}
},
unfreeze: () => {
if (gridRef.current?.unfreeze) {
gridRef.current.unfreeze();
}
},
}));
Performance
monitorImagesLoaded only when necessaryResponsive Design
Image Loading
monitorImagesLoaded when your grid contains imagesCheck the demo in the demo/ directory for more examples, including:
Run the component's tests:
npm test
FAQs
A Pinterest-style grid layout component built on top of @zapperwing/pinterest-view
We found that masonry-grid-component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.