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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mshafiqyajid/react-file-upload

v0.2.1

Published

Headless file upload hook and styled drag-and-drop component for React. Accessible, fully typed, zero dependencies.

Downloads

330

Readme

@mshafiqyajid/react-file-upload

Headless file upload hook and styled drag-and-drop component for React. Accessible, fully typed, zero runtime dependencies.

Install

npm install @mshafiqyajid/react-file-upload

Headless usage

import { useFileUpload } from "@mshafiqyajid/react-file-upload";

function MyUploader() {
  const { getRootProps, getInputProps, isDragOver, files, removeFile } =
    useFileUpload({
      multiple: true,
      accept: "image/*",
      maxSize: 5 * 1024 * 1024,
      onFiles: ({ accepted, rejected }) => {
        console.log("accepted", accepted);
        console.log("rejected", rejected);
      },
    });

  return (
    <div {...getRootProps()}>
      <input {...getInputProps()} />
      {isDragOver ? "Drop files here" : "Drag files or click to browse"}
      <ul>
        {files.map((f, i) => (
          <li key={i}>
            {f.name} <button onClick={() => removeFile(i)}>Remove</button>
          </li>
        ))}
      </ul>
    </div>
  );
}

Styled usage

import { FileUploadStyled } from "@mshafiqyajid/react-file-upload/styled";
import "@mshafiqyajid/react-file-upload/styles.css";

function App() {
  return (
    <FileUploadStyled
      multiple
      accept="image/*"
      maxSize={5 * 1024 * 1024}
      variant="dropzone"
      size="md"
      showPreview
      onFiles={({ accepted }) => console.log(accepted)}
    />
  );
}

Async uploader (with progress, abort, retry)

Pass an uploader to upload accepted files automatically. Each file becomes an UploadItem with status: "queued" | "uploading" | "success" | "error" | "aborted" and a progress you control by calling ctx.onProgress(fraction). Files honor ctx.signal for abort.

<FileUploadStyled
  multiple
  uploader={async (file, { signal, onProgress }) => {
    const xhr = new XMLHttpRequest();
    xhr.upload.onprogress = (e) => e.lengthComputable && onProgress(e.loaded / e.total);
    signal.addEventListener("abort", () => xhr.abort());

    return await new Promise<{ url: string }>((resolve, reject) => {
      xhr.onload = () => resolve(JSON.parse(xhr.responseText));
      xhr.onerror = () => reject(new Error("upload failed"));
      xhr.open("POST", "/api/upload");
      const fd = new FormData();
      fd.append("file", file);
      xhr.send(fd);
    });
  }}
  concurrency={3}
  onUpload={(item) => console.log(item.status, item.progress)}
/>

Headless consumers also get uploads, retryUpload(id), abortUpload(id), and abortAll().

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | variant | "dropzone" \| "button" | "dropzone" | Upload widget style | | multiple | boolean | false | Allow multiple files | | accept | string | — | Accepted file types (MIME or extension) | | maxSize | number | — | Max file size in bytes | | maxFiles | number | — | Max number of files | | disabled | boolean | false | Disable interaction | | size | "sm" \| "md" \| "lg" | "md" | Size variant | | tone | "neutral" \| "primary" | "neutral" | Color tone | | showPreview | boolean | true | Show file preview thumbnails | | browseText | string | "Browse" | Text on the browse button | | uploader | (file, ctx) => Promise<TResult> | — | Async uploader; enables progress + retry/abort | | concurrency | number | 3 | Max parallel uploads | | autoUpload | boolean | true | Start uploading on file accept | | onFiles | ({ accepted, rejected }) => void | — | Fired on file selection | | onUpload | (item) => void | — | Fired on upload state changes | | onRemove | (file) => void | — | Fired when a file is removed | | onRetry | (item) => void | — | Fired when an upload is retried | | renderPreview | (file) => ReactNode | — | Custom preview renderer |

Links