npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

reactjs-file-preview

v1.0.11

Published

Effortlessly preview images, videos, and PDFs in your React applications with MyFilePreview. This lightweight and customizable component intelligently detects file types and displays them.

Readme

reactjs-file-preview – A Smart File Preview Component for React

npm version npm npm

Effortlessly preview images, videos, and PDFs in your React applications with reactjs-file-preview. This lightweight and customizable component intelligently detects file types and displays:

  • Images – Render high-quality previews for JPG, PNG, GIF, and more.
  • Videos – Play MP4, WebM, and other video formats directly in the preview.
  • PDFs – Generate a thumbnail preview of the first page for quick viewing.
  • Auto-Detection – Handles file URLs, local files, and external sources.
  • Seamless Integration – Works with any React project with minimal setup.

Perfect for file upload interfaces, document management systems, and media galleries! 🚀

Live Demo: https://akshay2002singh.github.io/reactjs-file-preview/


📦 Installation

NPM

To install the latest stable version:

npm install reactjs-file-preview
# OR
yarn add reactjs-file-preview

🚀 Usage

Basic Example (Remote URL)

import React from "react";
import FilePreview from "reactjs-file-preview";

const App = () => {
  return (
    <div>
      <h2>File Preview Example</h2>
      <FilePreview preview="https://example.com/sample.pdf" />
    </div>
  );
};

export default App;

Example with Placeholder and Error Image

<FilePreview
  preview="https://example.com/sample.jpg"
  placeHolderImage="https://example.com/placeholder.png"
  errorImage="https://example.com/error.png"
/>

Local File Example

import sampleImg from "../assets/exampleImage.png";

<div style={{ width: "300px" }}>
  <FilePreview preview={sampleImg} />
</div>;

File Input Example

<input
    type="file"
    onChange={(e) => e.target.files && setFile(e.target.files[0])}
    style={{ marginBottom: "1rem" }}
  />

<div style={{ width: "600px", height: "400px", borderRadius: '12px', overflow:'hidden' }}>
  <FilePreview
    preview={file ?? ""}
    placeHolderImage="https://placehold.co/600x400/fff/000?text=Placeholder"
    errorImage="https://placehold.co/600x400/fff/FF0000?text=Error"
  />
</div>

Example with Custom Axios Instance

If your files require authentication or are behind CORS restrictions, you can pass a custom Axios instance:

import axios from "axios";

const customAxios = axios.create({
  headers: {
    Authorization: "Bearer YOUR_ACCESS_TOKEN",
  },
});

<FilePreview
  preview="https://example.com/protected-file.pdf"
  axiosInstance={customAxios}
/>;

📂 Supported Formats

reactjs-file-preview currently supports the following file extensions:

  • Images: jpg, jpeg, png, gif, webp
  • Videos: mp4, webm, ogg
  • Documents: `pdf

Props

Available Props

| Prop Name | Type | Required | Description | | ------------------ | ------ | -------- | ------------------------------------------------------------------------------------------------------------------- | | preview | string | File | null | ✅ | The source of the file to preview. Supports: Remote URL (string)Local file import via bundler (import sample from "./file.png") File object from an <input type="file" />null (shows the placeholder if provided) | | clarity | string | ❌ | Defines clarity of the file being previewed. Defaults to 1000. Higher the value, more the loading time of the file. | | placeHolderImage | string | ❌ | URL of an image to display if no file is provided. | | errorImage | string | ❌ | URL of an image to display if the file fails to load. | | fileType | string | ❌ | Type of the file (image, video, pdf). If not provided, the type will be auto-detected. | | axiosInstance | object | ❌ | Custom Axios instance for fetching files, useful for handling authentication or CORS issues. |

ℹ️ Note:
If preview is not provided (or is null) and a placeHolderImage is supplied, the placeholder image will be shown automatically.

This component will automatically detect the file type and display the appropriate preview. 🎉


🎯 Why Use reactjs-file-preview?

  • 📂 Multi-format support – Works with images, videos, and PDFs.
  • 🔍 Auto-detection – No need to specify file types manually.
  • 🛠️ Customizable – Supports placeholders, error images, and authentication.
  • 🏆 Lightweight – Minimal dependencies for fast performance.
  • 🚀 Easy to integrate – Works with any React project effortlessly.

Start using reactjs-file-preview today and enhance your file preview experience! 🎉