React Photo Album is a responsive React component designed for building dynamic photo galleries, currently at version 3.6.0. It offers three distinct layout options: rows, columns, and masonry, each powered by sophisticated dynamic programming algorithms to ensure optimal arrangement and visual balance. Its rows layout, inspired by the Knuth and Plass algorithm, minimizes deviations from a target row height, preventing stretched images or awkward last rows. The columns layout dynamically balances content, while masonry places photos into the shortest column. The library is actively maintained with regular updates and emphasizes performance, SSR compatibility, built-in TypeScript definitions, and automatic responsive image handling. It serves as a re-engineered alternative to `react-photo-gallery`, supporting React 18+ and Node 18+ and requiring modern ESM-compatible bundlers.
npm install react-photo-albumVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic responsive photo gallery using the RowsPhotoAlbum component with dynamic photo data, custom row height, spacing, and a click handler.
Upgrade your Node.js installation to v18 or newer, and your React installation to v18 or newer. Ensure `@types/react` is also updated if using TypeScript.
Configure your project's bundler to correctly handle ESM imports, or ensure you are using a modern build toolchain. Avoid `require()` statements for this package.
For the aggregate PhotoAlbum component, add `import 'react-photo-album/styles.css';`. For layout-specific components (e.g., RowsPhotoAlbum), add `import 'react-photo-album/rows.css';`.
Consult the official documentation for the updated `render` functions and `componentsProps` API. Update custom rendering logic to use the new prop names.
Ensure all `photo` objects in the `photos` array have valid `width` and `height` properties (e.g., `{ src: '...', width: 800, height: 600 }`).Ensure each `photo` object in the `photos` array has a unique `id` property, or provide a custom `key` prop to the PhotoAlbum component that guarantees uniqueness.
Change `const PhotoAlbum = require('react-photo-album');` to `import PhotoAlbum from 'react-photo-album';` (or specific named imports if applicable).Add the appropriate CSS import: `import 'react-photo-album/styles.css';` for the aggregate `PhotoAlbum` component, or `import 'react-photo-album/rows.css';` (or `columns.css`/`masonry.css`) for layout-specific components.
Ensure that each object in the `photos` array has a unique `id` property, or explicitly provide a unique `key` prop for each photo object. This issue was specifically addressed for duplicate photos in v3.5.1.
Verify that all `Photo` objects in your `photos` array have valid `width` and `height` numerical values greater than zero.