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](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage01.018d1d35.jpg&w=3840&q=75)
![Purple petaled flowers near a mountain](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage02.cf33eff7.jpg&w=3840&q=75)
![A person pointing at a beige map](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage03.cdc32b45.jpg&w=3840&q=75)
![Two hikers walking toward a snow-covered mountain](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage04.9a1f6335.jpg&w=3840&q=75)
![A silver and black coffee mug on a brown wooden table](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage05.d7ef12b4.jpg&w=3840&q=75)
![A worm's eye view of trees at night](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage06.4ab952e3.jpg&w=3840&q=75)
![A pine tree forest near a mountain at sunset](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage07.ac608196.jpg&w=3840&q=75)
![Silhouette photo of three hikers near tall trees](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage08.95e095b5.jpg&w=3840&q=75)
![A person sitting near a bonfire surrounded by trees](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage09.fa6c4764.jpg&w=3840&q=75)
![Green moss on gray rocks in a river](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage10.411ea655.jpg&w=3840&q=75)
![Landscape photography of mountains](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage11.f3ea483a.jpg&w=3840&q=75)
![A pathway between green trees during daytime](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage12.5a9347ea.jpg&w=3840&q=75)
![A man wearing a black jacket and backpack standing on a grass field during sunset](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage13.ce46dd98.jpg&w=3840&q=75)
![Green pine trees under white clouds during the daytime](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage14.68b2812c.jpg&w=3840&q=75)
![A hiker sitting near the cliff](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage15.4461facf.jpg&w=3840&q=75)
![A tall mountain with a waterfall running down its side](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage16.5ad17d8b.jpg&w=3840&q=75)
![Blue mountains](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage17.a242e897.jpg&w=3840&q=75)
![Green trees on a brown mountain under a blue sky during the daytime](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage18.0479bde8.jpg&w=3840&q=75)
![A red flower on a green grass field during the daytime](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage19.ab7b61f4.jpg&w=3840&q=75)
![A sign warning people not to disturb nature](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage20.f62571df.jpg&w=3840&q=75)
![A small creek in Yosemite National Park](https://assets.react-photo-album.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fimage21.14c9bee0.jpg&w=3840&q=75)