React Image Viewer

3.2.2 · active · verified Tue Apr 21

react-viewer is a dedicated image viewing component for React applications, providing a customizable and feature-rich lightbox experience. It is currently in version 3.2.2 and sees active development with frequent minor releases addressing bugs and adding features. A major version 4.0 is planned to re-introduce Server-Side Rendering (SSR) support. Key differentiators include its native React implementation, utilizing React Hooks and `ReactDOM.createPortal` for modern React patterns, offering a robust alternative to general-purpose JavaScript viewer libraries like Viewer.js within a React ecosystem. It supports various image operations like zooming, rotating, scaling, and offers extensive customization through props for toolbar, navbar, and general UI behavior. It ships with TypeScript type definitions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate react-viewer into a functional React component, using state to control the viewer's visibility and passing an array of image objects. It includes basic interaction props for zoom, rotate, and download.

import * as React from 'react';
import Viewer from 'react-viewer';

function App() {
  const [visible, setVisible] = React.useState(false);
  const images = [
    { src: 'https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg', alt: 'Forest' },
    { src: 'https://images.unsplash.com/photo-1507525428034-b723cf961c3e', alt: 'Beach' }
  ];

  return (
    <div>
      <button onClick={() => { setVisible(true); } } style={{ padding: '10px 20px', fontSize: '16px', cursor: 'pointer' }}>
        Show Images
      </button>
      <Viewer
        visible={visible}
        onClose={() => { setVisible(false); } }
        images={images}
        activeIndex={0}
        downloadable={true}
        zoomable={true}
        rotatable={true}
        scalable={true}
        noFooter={false}
      />
    </div>
  );
}

view raw JSON →