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.
npm install react-viewerVerified import paths — ran on the pinned version, not inferred.
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.
Ensure `react` and `react-dom` are updated to version `16.8.0` or higher. Refactor class components using `react-viewer` to functional components if needed to leverage Hooks effectively, or adjust prop usage.
Avoid using `react-viewer` in SSR contexts with 3.x. If SSR is critical, consider conditional rendering to only mount `react-viewer` on the client-side or wait for the 4.0 release. Consult the roadmap for 4.0 development.
For versions `3.0.x` and `>=3.2.1`, no explicit CSS import is generally needed as styles are bundled or injected. For `v3.2.0` specifically, ensure `import 'react-viewer/dist/index.css';` is present. Always test styling carefully after `react-viewer` updates.
Upgrade `react` and `react-dom` packages to version `16.8.0` or higher.
Ensure your project build setup (e.g., Webpack, Babel) correctly handles ESM modules, especially if targeting older Node.js versions or CommonJS. For client-side React apps, this is usually handled automatically. If running server-side, you might need to configure your bundler to transpile `node_modules`.
For `react-viewer@3.2.0`, add `import 'react-viewer/dist/index.css';` to your entry point. For `v3.0.x` and `>=3.2.1`, this import is typically not needed, as styles are handled internally. Check the `react-viewer` release notes for your exact version to confirm CSS import requirements.