Skip to solution
mediumMachine Coding

Build an Image Gallery with lightbox

760 views
01

Understand the problem

Build a responsive image grid that opens a full-screen lightbox.

ReactGalleryLightbox
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Solve in

Building an Image Gallery with Lightbox in React

Mental model: A grid of thumbnails plus an overlay (lightbox) that shows one image at a time. The lightbox is driven by a single piece of state: the index of the open image (or null when closed). Prev/next change the index with wrap; Escape and backdrop click

Solution ready — 2 min read

Classified // press E to declassify

04

React solution

Complete solutionRun Playground
import React from 'react';
import ImageGallery from './src/ImageGallery';

// Use CSS gradients as stand-in "images" so the demo needs no network.
const images = [
  'linear-gradient(135deg,#2563eb,#7c3aed)',
  'linear-gradient(135deg,#16a34a,#22d3ee)',
  'linear-gradient(135deg,#d97706,#dc2626)',
  'linear-gradient(135deg,#7c3aed,#ec4899)',
  'linear-gradient(135deg,#0891b2,#14b8a6)',
  'linear-gradient(135deg,#f59e0b,#ef4444)',
];

export default function App() {
  return (
    <div style={{ fontFamily: 'sans-serif', padding: 20 }}>
      <h1>Image Gallery Demo</h1>
      <ImageGallery images={images} />
    </div>
  );
}
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 34 of 87 decoded in the Frontend Machine Coding track. One more won't hurt.

Back to track