npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

masonry-gridify

v1.0.3

Published

A lightweight, responsive, and customizable Masonry grid component for React.

Downloads

5

Readme

Masonry React Component

A lightweight, responsive, and customizable Masonry grid component for React.

Features

  • Auto-calculates columns based on container width.
  • Resizes dynamically when the window size changes.
  • Provides smooth transitions.
  • Uses ResizeObserver for real-time adjustments.

Installation

npm install masonry-gridify
// or
npm install --save masonry-gridify
// or
yarn add masonry-gridify

Usage

If height is not defined

It takes the clientHeight of each element even if height is defined or not. So no need to explicitly define the height.

If height is defined

import Masonry from "masonry-gridify";

const Example = () => {
  return (
    <Masonry gap={10} width={"250px"}>
      <div style={{ height: "150px", background: "red" }}></div>
      <div style={{ height: "200px", background: "blue" }}></div>
      <div style={{ height: "250px", background: "green" }}></div>
      <div style={{ height: "180px", background: "yellow" }}></div>
    </Masonry>
  );
};

export default Example;

Features

Number of Columns

import Masonry, { columns } from "masonry-gridify";

Gets the number of columns displayed in screen.

Default Transition

<Masonry gap={10} width={"250px"} defaultTransition={true}></Masonry>

Enables a default transition effect of 0.3s ease.

Custom Loading

<Masonry gap={10} width={"250px"} loading={<p>Loading...</p>}></Masonry>

Displays a custom loading indicator while the grid is being prepared.

Custom transition

<Masonry gap={10} width={"250px"} transition={"1s ease-in-out"}></Masonry>

Applies a custom transition style.


Props

| Prop Name | Type | Required | Description | | ------------------- | ------------- | -------- | ------------------------------------------------------------- | | gap | number | ✅ | The gap between the grid items (in pixels). | | width | string | ✅ | Minimum column width (supports px, rem, em, etc.). | | children | JSX.Element | ✅ | Content elements to arrange. | | loading | JSX.Element | ❌ | A loading indicator while the masonry grid is being prepared. | | transition | string | ❌ | Custom transition style. | | defaultTransition | boolean | ❌ | Enables default transition of 0.3s ease. |


How It Works

  1. Dynamic Column Calculation:

    • Calculates columns based on container width and column width.
    • Uses ResizeObserver and window resize events for responsiveness.
  2. Element Positioning:

    • Uses CSS transforms to adjust element positions.
    • Maintains vertical gaps between items.
    • Handles overlapping elements through margin adjustments.
  3. Performance:

    • Debounced resize handling (200ms delay).
    • RequestAnimationFrame for smooth transitions.
    • Cleanup of observers and event listeners.

Debugging Guide

Common Issues & Fixes

  1. No items appear

    • Ensure children are passed correctly.
    • Check for missing gap or width props.
  2. Elements are overlapping or positioned incorrectly

    • Try refreshing the page. If the issue persists, inspect the elements in DevTools.
  3. Layout Not Updating on Resize

    • Check if the ResizeObserver is working in your browser’s dev tools.
    • Try forcing an update by changing the window size.
  4. Flickering During Transitions

    Copy paste this code in your item. If the issue persists, you can always create a pull request.

    // Add this to your masonry items' CSS:
    .masonryItem {
      will-change: transform;
      backface-visibility: hidden;
    }

Contribution

If you find any issues or want to contribute, feel free to submit a pull request.

Happy Coding! 🚀