Skip to content
react-mediadrop
Esc
navigateopen⌘Jpreview

Accepting file types

Restrict the dropzone to specific MIME types with restrictions.accept.

Restrict the dropzone to specific file types with restrictions.accept.

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

export function AcceptExample() {
	const { acceptedFiles, rejectedFiles, getRootProps, getInputProps } =
		useMediaDrop({ restrictions: { accept: ["image/png", "image/jpeg"] } });

	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.map((e) => e.message).join(", ")}
					</li>
				))}
			</ul>
		</div>
	);
}

accept takes an exact MIME type ("image/png"), a wildcard ("image/*"), a file extension (".png"), or an array/comma-separated string of any of those. See Validation for the full shape.

Last updated on September 5, 2026

Was this page helpful?