Next.js Image

If your project is based on Next.js and you'd like to use the next/image component instead of the standard <img> element, you can easily accomplish this with the render.image function:

"use client";

import Image from "next/image";
import {
  RenderImageContext,
  RenderImageProps,
  RowsPhotoAlbum,
} from "react-photo-album";
import "react-photo-album/rows.css";

import photos from "@/components/photos";

function renderNextImage(
  { alt = "", title, sizes }: RenderImageProps,
  { photo, width, height }: RenderImageContext,
) {
  return (
    <div
      style={{
        width: "100%",
        position: "relative",
        aspectRatio: `${width} / ${height}`,
      }}
    >
      <Image
        fill
        src={photo}
        alt={alt}
        title={title}
        sizes={sizes}
        placeholder={"blurDataURL" in photo ? "blur" : undefined}
      />
    </div>
  );
}

export default function PhotoGallery() {
  return (
    <RowsPhotoAlbum
      photos={photos}
      render={{ image: renderNextImage }}
      defaultContainerWidth={1200}
      sizes={{
        size: "1168px",
        sizes: [
          { viewport: "(max-width: 1200px)", size: "calc(100vw - 32px)" },
        ],
      }}
    />
  );
}

Live Demo

Hiking boots
Purple petaled flowers near a mountain
A person pointing at a beige map
Two hikers walking toward a snow-covered mountain
A silver and black coffee mug on a brown wooden table
A worm's eye view of trees at night
A pine tree forest near a mountain at sunset
Silhouette photo of three hikers near tall trees
A person sitting near a bonfire surrounded by trees
Green moss on gray rocks in a river
Landscape photography of mountains
A pathway between green trees during daytime
A man wearing a black jacket and backpack standing on a grass field during sunset
Green pine trees under white clouds during the daytime
A hiker sitting near the cliff
A tall mountain with a waterfall running down its side
Blue mountains
Green trees on a brown mountain under a blue sky during the daytime
A red flower on a green grass field during the daytime
A sign warning people not to disturb nature
A small creek in Yosemite National Park

Sandbox

Edit on StackBlitz

Source Code

View on GitHub