# react-masonry-list

> A Masonry component implemented through css grid, fast and responsive.

Latest version **1.0.6** (published 2023-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-masonry-list
pnpm add react-masonry-list
yarn add react-masonry-list
bun add react-masonry-list
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2023-12-17 |
| First published | 2021-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 53.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Margaux7 |
| Maintainers | margaux |
| Keywords | react, masonry, layout, component, grid |

## Links

- npm: https://www.npmjs.com/package/react-masonry-list
- Repository: https://github.com/Margaux7/react-masonry-list
- npm.io page: https://npm.io/package/react-masonry-list

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2023-12-17
- 1.0.5 — 2023-09-10
- 1.0.4 — 2023-04-29
- 1.0.3 — 2023-03-05
- 1.0.2 — 2022-08-03
- 1.0.1 — 2022-08-03
- 1.0.0 — 2022-07-11
- 0.1.6 — 2022-06-01
- 0.1.5 — 2021-10-25
- 0.1.4 — 2021-10-25
- 0.1.3 — 2021-10-25
- 0.1.1 — 2021-10-24
- 0.1.0 — 2021-10-24

## README

# React Masonry List

[![npm](https://img.shields.io/npm/v/react-masonry-list.svg?style=flat-square)](https://www.npmjs.com/package/react-masonry-list)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A Masonry component implemented through [css grid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout), fast and responsive.
:star2: Each element first fills the column with the largest remaining space in the vertical direction, which will ensure that the height difference of each column is minimal.

![](https://user-images.githubusercontent.com/16912880/177976842-35ca3306-33ef-44c1-ab23-b19fb2f4366f.gif)

:point_right: [demo page](https://react-masonry-list.vercel.app/)

## Install

`npm install react-masonry-list --save`

Or use yarn
`yarn add react-masonry-list`

## Usage

```js
import Layout from 'react-masonry-list';

const items = [
  //...
];

// If item contains img elements, don't forget set img's width. In order to get a better display effect, you can also set img's `object-fit` to `contain`.

const List = () => {
  return (
    <Layout
      minWidth={100}
      items={items.map((item) => (
        <div key={item.id}>...</div>
      ))}
    ></Layout>
  );
};
```

### Use with NextJS

Because it's a client side only component, when using it with NextJS, you need to import it by `dynamic` API:

```js
import dynamic from 'next/dynamic';

const Layout = dynamic(() => import('react-masonry-list'), {
  ssr: false,
});

const items = [
  //...
];

// If item contains img elements, don't forget set img's width. In order to get a better display effect, you can also set img's `object-fit` to `contain`.

const List = () => {
  return (
    <Layout
      minWidth={100}
      items={items.map((item) => (
        <div key={item.id}>...</div>
      ))}
    ></Layout>
  );
};
```

## Props

| name      | type             | required | default | description                              |
| --------- | ---------------- | -------- | ------- | ---------------------------------------- |
| items     | react node array | No       | []      | The items you want to render             |
| colCount  | number           | No       | 3       | Column count                             |
| gap       | number           | No       | 10      | The size(px) of the gap between elements |
| minWidth  | number           | No       | 300     | The min width(px) of columns             |
| className | string           | No       | \       | Custom class name of layout container    |

## Browser compatibility

Refer to https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns#browser_compatibility

---
_Source: https://npm.io/package/react-masonry-list · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
