Clawdy
Api reference

@clawdyup/react

React components and hooks API reference

generateUploadButton

Returns a typed UploadButton component bound to your FileRouter. Use this when you only need the button component.

import { generateUploadButton } from "@clawdyup/react";
import type { FileRouter } from "@/server/clawdy";

export const UploadButton = generateUploadButton<FileRouter>();

Usage

<UploadButton
  endpoint="profileImage"
  onClientUploadComplete={(res) => {
    console.log("Uploaded files:", res);
  }}
  onUploadError={(error) => {
    console.error("Upload failed:", error.message);
  }}
/>

generateUploadDropzone

Returns a typed UploadDropzone component bound to your FileRouter. Use this when you only need the dropzone component.

import { generateUploadDropzone } from "@clawdyup/react";
import type { FileRouter } from "@/server/clawdy";

export const UploadDropzone = generateUploadDropzone<FileRouter>();

Usage

<UploadDropzone
  endpoint="documentUploader"
  onClientUploadComplete={(res) => {
    console.log("Uploaded files:", res);
  }}
  onUploadError={(error) => {
    console.error("Upload failed:", error.message);
  }}
/>

generateReactHelpers

Returns all React primitives at once: the UploadButton component, the UploadDropzone component, and the useClawdy hook, all typed to your FileRouter.

import { generateReactHelpers } from "@clawdyup/react";
import type { FileRouter } from "@/server/clawdy";

export const { UploadButton, UploadDropzone, useClawdy } =
  generateReactHelpers<FileRouter>();

useClawdy

A hook for building fully custom upload UIs. Returned by generateReactHelpers.

const { startUpload, isUploading } = useClawdy(endpoint, opts);

Parameters

ParameterTypeDescription
endpointkeyof FileRouterThe name of the route in your FileRouter.
optsobject | undefinedOptional callbacks (see below).

Options

OptionTypeDescription
onClientUploadComplete(res: UploadFileResponse[]) => voidCalled when all files finish uploading.
onUploadError(error: Error) => voidCalled if the upload fails.
onUploadProgress(progress: number) => voidCalled with the upload progress percentage (0-100).
onUploadBegin(fileName: string) => voidCalled when each file begins uploading.

Returns

PropertyTypeDescription
startUpload(files: File[], options?: { input?: object }) => Promise<UploadFileResponse[]>Trigger the upload. Pass metadata via options.input matching the route's .input() schema.
isUploadingbooleanWhether an upload is currently in progress.

Example

function CustomUploader() {
  const { startUpload, isUploading } = useClawdy("profileImage", {
    onClientUploadComplete: (res) => {
      console.log("Done!", res);
    },
    onUploadError: (err) => {
      alert(err.message);
    },
    onUploadProgress: (progress) => {
      console.log(`${progress}% uploaded`);
    },
  });

  return (
    <div>
      <input
        type="file"
        onChange={async (e) => {
          const files = Array.from(e.target.files ?? []);
          await startUpload(files, { input: { userId: "user_123" } });
        }}
        disabled={isUploading}
      />
      {isUploading && <p>Uploading...</p>}
    </div>
  );
}

UploadButton Props

PropTypeRequiredDescription
endpointkeyof FileRouterYesThe upload route to use.
inputobjectNoMetadata object matching the route's .input() Zod schema.
onClientUploadComplete(res: UploadFileResponse[]) => voidNoCalled when all files have been uploaded successfully.
onUploadError(error: Error) => voidNoCalled when the upload fails.
onUploadProgress(progress: number) => voidNoCalled with the upload progress percentage (0-100).
onUploadBegin(fileName: string) => voidNoCalled when each individual file starts uploading.
onBeforeUploadBegin(files: File[]) => File[]NoCalled before the upload begins. Return a modified array of files (e.g. to rename or filter).
disabledbooleanNoDisables the button when true.
classNamestringNoCSS class name applied to the root element.

UploadDropzone Props

PropTypeRequiredDescription
endpointkeyof FileRouterYesThe upload route to use.
inputobjectNoMetadata object matching the route's .input() Zod schema.
onClientUploadComplete(res: UploadFileResponse[]) => voidNoCalled when all files have been uploaded successfully.
onUploadError(error: Error) => voidNoCalled when the upload fails.
onUploadProgress(progress: number) => voidNoCalled with the upload progress percentage (0-100).
onUploadBegin(fileName: string) => voidNoCalled when each individual file starts uploading.
onBeforeUploadBegin(files: File[]) => File[]NoCalled before the upload begins. Return a modified array of files (e.g. to rename or filter).
disabledbooleanNoDisables the dropzone when true.
classNamestringNoCSS class name applied to the root element.

On this page