How to build a React.js image viewer

Table of contents

    Need to build a responsive image viewer in React? This step-by-step tutorial shows you how to use Nutrient Web SDK to create a fast, customizable image viewer that works with JPEG, PNG, and TIFF files. You’ll learn how to scaffold a React app with Vite, integrate the SDK, and display images with a polished user interface (UI), plus add extra capabilities like annotations, cropping, and eSignatures.
    How to build a React.js image viewer
    Summary

    This tutorial shows you how to build an image viewer in React using Nutrient Web SDK. You’ll start by scaffolding a React project with Vite, and then integrate the SDK to render image files like PNG, JPG, and TIFF inside a clean, responsive viewer.

    • Supports major formats — JPEG, PNG, and TIFF
    • Zero plugins required — Runs in all modern browsers and mobile devices
    • Includes annotation tools — Markup images with highlights, shapes, notes, and more
    • Ready for production — Secure, scalable, and easily customizable for your UI
    • React-first developer experience — Works with modern tooling like Vite and hooks

    Use it to build an internal tool, document portal, or image-based app with advanced collaboration features.

    What is a React image viewer?

    A React image viewer lets you render and view images in a web browser without the need to download it to your hard drive or use an external application like an image reader.

    Nutrient React image viewer

    We offer a commercial React.js image viewer library that can easily be integrated into your web application. The React image viewer library supports rendering JPEG, PNG, and TIFF files in any modern browser and on any mobile device without any plugins. It offers developers a way to quickly embed a highly configurable image or PDF viewer with a beautiful UI in any web application.

    • A prebuilt and polished UI for an improved user experience
    • 15+ prebuilt annotation tools to enable document collaboration
    • Support for more file types with client-side PDF, MS Office, and image viewing
    • Dedicated support from engineers to speed up integration

    Example of our React image viewer

    To see our image viewer in action, upload a JPG, PNG, or TIFF file by selecting Choose Example > Open Document. Once your image is displayed in the viewer, you can try drawing freehand, adding a note, or applying a crop or an eSignature.

    Requirements to get started

    To get started, you’ll need:

    Setting up a new React project with Vite

    Use vite(opens in a new tab) to scaffold out a simple React application:

    Terminal window
    npm create vite@latest nutrient-react-example -- --template react
    cd nutrient-react-example

    Install Nutrient Web SDK

    Next, install the @nutrient-sdk/viewer package:

    Terminal window
    npm i @nutrient-sdk/viewer

    Copying SDK assets to the public directory

    Nutrient Web SDK loads its WebAssembly and supporting files from a local path, so you need to copy them to the public folder. Start by installing the required copy plugin:

    Terminal window
    npm install -D rollup-plugin-copy

    Then, update your Vite configuration (vite.config.ts) to copy the SDK’s asset files during build:

    import { defineConfig } from "vite";
    import react from "@vitejs/plugin-react";
    import copy from "rollup-plugin-copy";
    export default defineConfig({
    plugins: [
    copy({
    targets: [
    {
    src: "node_modules/@nutrient-sdk/viewer/dist/nutrient-viewer-lib",
    dest: "public/",
    },
    ],
    hook: "buildStart",
    }),
    react(),
    ],
    });

    Displaying a PDF

    Now that everything is set up, you’ll render an image file using the Nutrient SDK.

    Basic usage in App.tsx:

    import { useEffect, useRef } from "react";
    function App() {
    const containerRef = useRef(null);
    useEffect(() => {
    const container = containerRef.current;
    let cleanup = () => {};
    (async () => {
    const NutrientViewer = (await import("@nutrient-sdk/viewer")).default;
    // Unload any previous instance.
    NutrientViewer.unload(container);
    if (container && NutrientViewer) {
    NutrientViewer.load({
    container,
    document: "image.png", // Replace with your image path
    baseUrl: `${window.location.protocol}//${
    window.location.host
    }/${import.meta.env.PUBLIC_URL ?? ""}`,
    });
    }
    cleanup = () => {
    NutrientViewer.unload(container);
    };
    })();
    return cleanup;
    }, []);
    return <div ref={containerRef} style={{ height: "100vh", width: "100vw" }} />;
    }
    export default App;

    You can also render a different file by changing the document path or making it dynamic.

    Once everything is configured, start your app:

    Terminal window
    npm run dev

    You’ll now see the Nutrient Web SDK UI rendering your image file inside the browser!

    Note that because Nutrient is a commercial product, you’ll see a Nutrient Web SDK evaluation notice on the document. To get a license key, contact Sales.

    Resulting page

    Adding even more capabilities

    Once you’ve deployed your viewer, you can start customizing it to meet your specific requirements or easily add more capabilities. To help you get started, here are some of our most popular React.js guides:

    Conclusion

    You should now have our React image viewer up and running in your web application. If you hit any snags, don’t hesitate to reach out to our Support team for help.

    We created similar how-to blog posts using different web frameworks and libraries:

    To see a list of all web frameworks, start your free trial. Or, launch our demo to see our viewer in action.

    FAQ

    What is a React image viewer?

    A React image viewer allows you to render and view images directly in a web browser without needing additional software.

    Why use Nutrient for a React image viewer?

    Nutrient offers a feature-rich, customizable image viewer that supports various image formats and integrates seamlessly into React applications.

    How do I integrate Nutrient into my React project?

    Install Nutrient via npm or Yarn, add it to your project’s public directory, and use a component wrapper to display images.

    What image formats are supported by Nutrient’s React image viewer?

    Nutrient supports JPEG, PNG, and TIFF image formats.

    Can I customize the Nutrient React image viewer?

    Yes. Nutrient’s React image viewer is highly customizable, allowing you to adjust the UI and functionality according to your needs.

    Hulya Masharipov

    Hulya Masharipov

    Technical Writer

    Hulya is a frontend web developer and technical writer at Nutrient who enjoys creating responsive, scalable, and maintainable web experiences. She’s passionate about open source, web accessibility, cybersecurity privacy, and blockchain.

    Explore related topics

    FREE TRIAL Ready to get started?