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

@uploadbox/react

v0.7.2

Published

React components and hooks for Uploadbox — UploadButton, UploadDropzone, useUploadbox

Readme

@uploadbox/react

React components and hooks for Uploadbox — UploadButton, UploadDropzone, and useUploadbox.

npm license

Installation

npm i @uploadbox/react @uploadbox/core

Peer dependencies: React 18 or 19.

Quick Start

1. Wrap your app with the provider

import { UploadboxProvider } from "@uploadbox/react";
import "@uploadbox/react/styles.css";

export default function App({ children }) {
  return (
    <UploadboxProvider apiUrl="/api/uploadbox">
      {children}
    </UploadboxProvider>
  );
}

2. Add an upload component

import { UploadButton, UploadDropzone } from "@uploadbox/react";

function MyPage() {
  return (
    <>
      <UploadButton
        endpoint="imageUploader"
        onClientUploadComplete={(files) => console.log("Uploaded:", files)}
        onUploadError={(err) => console.error(err)}
      />

      <UploadDropzone
        endpoint="imageUploader"
        onClientUploadComplete={(files) => console.log("Uploaded:", files)}
        onUploadError={(err) => console.error(err)}
      />
    </>
  );
}

useUploadbox Hook

For full control, use the hook directly:

import { useUploadbox } from "@uploadbox/react";

function CustomUploader() {
  const {
    startUpload,   // (files: File[]) => Promise<UploadedFile[]>
    isUploading,   // boolean
    progress,      // 0–100
    fileProgress,  // FileProgress[] — per-file details
    routeConfig,   // fetched route constraints
    abort,         // cancel current upload
  } = useUploadbox("imageUploader", {
    onClientUploadComplete: (files) => console.log(files),
    onUploadError: (err) => console.error(err),
    onUploadProgress: (e) => {
      console.log(`Overall: ${e.percent}%`);
      e.fileProgress.forEach((f) => {
        console.log(`${f.name}: ${f.percent}% — ${f.speed} B/s, ETA ${f.eta}s`);
      });
    },
  });

  return (
    <div>
      <input type="file" multiple onChange={(e) => startUpload([...e.target.files!])} />
      {isUploading && <p>Uploading... {progress}%</p>}
      <button onClick={abort} disabled={!isUploading}>Cancel</button>
    </div>
  );
}

Per-File Progress

Each entry in fileProgress contains:

| Field | Type | Description | |-------|------|-------------| | name | string | File name | | status | string | "pending" | "uploading" | "retrying" | "complete" | "error" | | percent | number | 0–100 | | speed | number | Bytes/sec (3-second sliding window) | | eta | number | Estimated seconds remaining | | retryCount | number | Number of retries so far | | error | string? | Error message if failed |

Hook Options

useUploadbox("endpoint", {
  onClientUploadComplete: (files) => {},
  onUploadError: (err) => {},
  onUploadProgress: (event) => {},
  onBeforeUploadBegin: (files) => files, // transform files before upload
  headers: { "x-custom": "value" },
  getFileMetadata: (file) => ({ userId: "123" }),
  ttlSeconds: 3600,
  retry: { maxRetries: 5, initialDelayMs: 2000, backoffMultiplier: 2, maxDelayMs: 60000 },
  // retry: false — to disable retries
});

Customization

Content Props

Override default labels on built-in components:

<UploadButton
  endpoint="imageUploader"
  content={{ button: "Choose Image", allowedContent: "PNG, JPG up to 4MB" }}
/>

<UploadDropzone
  endpoint="imageUploader"
  content={{ label: "Drop files here", button: "Browse", allowedContent: "Images up to 4MB" }}
/>

CSS Classes

All components accept a className prop. The default styles use these classes:

Button: .uploadbox-button, .uploadbox-progress-bar, .uploadbox-progress-bar-fill

Dropzone: .uploadbox-dropzone, .uploadbox-dropzone--dragover, .uploadbox-dropzone--uploading, .uploadbox-dropzone--complete, .uploadbox-dropzone--error

Styles

Import the default stylesheet:

import "@uploadbox/react/styles.css";

Or write your own — the components work without the default CSS.

Type-Safe Factories

Generate components that are typed to your file router:

import { generateUploadButton, generateUploadDropzone } from "@uploadbox/react";
import type { AppRouter } from "@/lib/uploadbox";

const UploadButton = generateUploadButton<AppRouter>();
const UploadDropzone = generateUploadDropzone<AppRouter>();

// `endpoint` is now typed to your router keys
<UploadButton endpoint="imageUploader" />

Multipart Uploads

Files larger than 10 MB are automatically uploaded in parts (10 MB each, 4 concurrent). No extra configuration needed — the hook and components handle this transparently.

Retry

Retries are enabled by default with exponential backoff:

// Default config
{
  maxRetries: 3,
  initialDelayMs: 1000,
  backoffMultiplier: 2,
  maxDelayMs: 30000,
}

Retryable errors: network failures, 408, 429, and 5xx responses. Disable with retry: false.

Hosted Mode

For the Uploadbox hosted platform, pass an API key to the provider:

<UploadboxProvider apiUrl="/api/uploadbox" apiKey="pk_live_xxx">
  {children}
</UploadboxProvider>

Related Packages

License

MIT