Use Lightbox

Use Lightbox

A React hook that provides state management for a dynamically loaded lightbox component using yet-another-react-lightbox.

src/hooks/use-lightbox.tsx

Usage

import useLightbox from '@/hooks/use-lightbox'
export default function Gallery() {
const { openLightbox, renderLightbox } = useLightbox()
return (
<>
<button onClick={openLightbox}>Open Lightbox</button>
{renderLightbox({
slides: [
{ src: '/images/photo1.jpg' },
{ src: '/images/photo2.jpg' },
{ src: '/images/photo3.jpg' },
],
})}
</>
)
}

API

Returns

  • openLightbox: Function to open the lightbox
  • renderLightbox: Function that renders the lightbox component with provided props

renderLightbox Props

Accepts all props from yet-another-react-lightbox except open and close, including:

Features

  • Dynamic import of lightbox component for code splitting
  • Manages open/closed state internally
  • Prevents unnecessary renders with interactive state tracking
  • Built on top of yet-another-react-lightbox for full-featured image galleries

Note

This hook is currently not used in the codebase but is available for implementing image lightbox functionality.

Support

Talk to the developers of this project to learn more

We have been building professional websites for big clients for over 15 years. Gallop templates and blocks is our best foundation for SEO websites and web apps.

© 2025 Web Plant Media, LLC