Skip to content
react-mediadrop
Esc
navigateopen⌘Jpreview

Max files

Cap how many files a dropzone accepts with restrictions.maxFiles.

Cap how many files a dropzone accepts with restrictions.maxFiles.

TSX
import { useMediaDrop } from "react-mediadrop";

export function MaxFilesExample() {
	const { acceptedFiles, rejectedFiles, getRootProps, getInputProps } =
		useMediaDrop({ restrictions: { maxFiles: 3 } });

	return (
		<div className="space-y-3">
			<div
				{...getRootProps()}
				className="cursor-pointer rounded-lg border-2 border-dashed border-zinc-300 px-6 py-10 text-center dark:border-zinc-700"
			>
				<input {...getInputProps()} />
				<p>Drag files here, or click to browse</p>
			</div>
			<ul className="space-y-2">
				{acceptedFiles.map((file) => (
					<li
						key={file.id}
						className="rounded-md border border-zinc-200 px-3 py-2 text-sm dark:border-zinc-800"
					>
						{file.name}{file.size.toLocaleString()} bytes
					</li>
				))}
				{rejectedFiles.map((file) => (
					<li
						key={file.id}
						className="rounded-md border border-red-200 px-3 py-2 text-sm dark:border-red-900/60"
					>
						{file.name}{file.size.toLocaleString()} bytes ·{" "}
						{file.errors[0]?.message}
					</li>
				))}
			</ul>
		</div>
	);
}

maxFiles is evaluated across the whole file list, not per file. Drop a batch bigger than the remaining slots and files fill the remaining slots in order — the overflow is rejected with too-many-files, not the whole batch. See Core concepts.

Last updated on September 5, 2026

Was this page helpful?