Back to cookbook

ChatGPT Prompt to Build a React Drag-and-Drop File Upload Component With Progress Bar

1 views Published

Make this prompt yours

Share

This React drag-and-drop file upload component prompt is built for developers who need a working uploader with a drop zone, file previews, and a live progress bar without hand-rolling the drag events, validation, and state logic from scratch. It's aimed at anyone building a form, dashboard, or admin panel in React who wants ChatGPT, Claude, or Gemini to generate a component that handles drag-over styling, multiple file selection, type and size validation, and upload progress in one pass.

The prompt pushes the model to think through the parts developers usually forget: what happens when a user drags a file type that isn't allowed, how the drop zone should look mid-hover versus at rest, how progress updates while an upload is in flight, and how errors surface without crashing the form. It asks for accessible markup (a keyboard-triggerable file input and an ARIA live region for status updates) alongside the drag-and-drop behavior, so the output works for more than mouse-only users.

If you already have a visual reference for how the upload zone should look, such as a Figma frame or a live page with a drop zone you like, Site to Prompt can turn that rendered design into a prompt you can merge with this one, so the component's behavior and its visual spec come from the same source.

Prompt template

Make this prompt yours

prompt-template
385 tokens
ROLE You are a senior front-end engineer who specializes in React component architecture and accessible UI. CONTEXT I'm building a [FORM / DASHBOARD / ADMIN PANEL] in React using [REACT VERSION, e.g. React 18 with function components] and [STYLING APPROACH, e.g. Tailwind CSS / CSS Modules / styled-components]. I need a file upload component that supports drag-and-drop in addition to a standard click-to-browse input. REQUIREMENTS - Accept these file types: [ALLOWED FILE TYPES, e.g. .png, .jpg, .pdf] - Enforce a max file size of [MAX FILE SIZE] and a max file count of [MAX FILE COUNT] - Show a visually distinct drop zone state when a file is dragged over it - Display a progress bar per file while it uploads, using [UPLOAD METHOD, e.g. an onUploadProgress callback from axios, or XMLHttpRequest progress events] - Show clear success and error states per file, including a retry option on failure - Accept the actual upload function as a prop so the component is backend-agnostic - Be keyboard accessible: the file input must be triggerable without a mouse, and status changes must be announced via an ARIA live region CONSTRAINTS - Use only [ALLOWED LIBRARIES, e.g. no third-party upload libraries, or "react-dropzone is allowed"] - Keep the component in [SINGLE FILE / SPLIT INTO SUBCOMPONENTS] - Match this file naming and folder convention: [YOUR CONVENTION] OUTPUT FORMAT 1. The complete component code in a single fenced code block, with inline comments explaining the drag event handlers and progress logic 2. A short list of the props the component expects and what each one does 3. One sentence noting any edge case the implementation does not handle, if any

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
302 tokens
ROLE You are a senior front-end engineer who specializes in React component architecture and accessible UI. CONTEXT I'm building an admin panel in React using React 18 with function components and Tailwind CSS. I need a file upload component that supports drag-and-drop in addition to a standard click-to-browse input. REQUIREMENTS - Accept these file types: .png, .jpg, .pdf - Enforce a max file size of 5MB and a max file count of 10 - Show a visually distinct drop zone state when a file is dragged over it - Display a progress bar per file while it uploads, using an onUploadProgress callback from axios - Show clear success and error states per file, including a retry option on failure - Accept the actual upload function as a prop so the component is backend-agnostic - Be keyboard accessible: the file input must be triggerable without a mouse, and status changes must be announced via an ARIA live region CONSTRAINTS - Use only built-in React hooks, no third-party upload libraries - Keep the component in a single file - Match this file naming convention: FileUploadZone.jsx OUTPUT FORMAT 1. The complete component code in a single fenced code block, with inline comments explaining the drag event handlers and progress logic 2. A short list of the props the component expects and what each one does 3. One sentence noting any edge case the implementation does not handle, if any

When to use it

  • You're adding a file upload field to a React form and want drag-and-drop on top of the standard file picker
  • You need to show per-file upload progress instead of a single spinner for the whole batch
  • You're building an admin panel or CMS where editors upload images, PDFs, or CSVs regularly
  • You want validation (file type, size limits, max file count) handled in the component instead of on the server only

Best practices

  • Specify the exact file types and size limits you need (e.g. "PNG/JPG under 5MB, max 10 files") instead of letting the model guess generic defaults
  • Tell the model which state library you're using (plain useState, Zustand, Redux) so the generated hooks match your codebase instead of introducing a new pattern
  • Ask for the upload function to be passed in as a prop or callback rather than hardcoded, so the component stays reusable across different backends
  • Request separate states for "dragging over", "uploading", "success", and "error" explicitly, since models often collapse these into a single boolean and lose useful UI feedback

Common mistakes

  • Not specifying whether uploads should be sequential or parallel, which leads to a progress bar that jumps erratically when multiple files are uploading at once
  • Leaving out keyboard accessibility requirements, so the model ships a drop zone that only works with a mouse
  • Forgetting to ask for cleanup logic (removing object URLs, aborting in-flight requests) when a component unmounts mid-upload
  • Accepting the first draft without testing drag-over behavior when a file is dragged from outside the browser window, which some generated handlers miss

FAQs

How do I make a React drag-and-drop upload component accessible?

Explicitly ask the model for a keyboard-triggerable file input (role="button" with tabIndex and an Enter key handler) and an ARIA live region that announces status changes. Without that instruction, most generated drop zones only respond to mouse drag events.

Should I use react-dropzone or build the drag-and-drop logic myself?

Either works; state your preference in the prompt. Asking for a library-free version keeps the component dependency-light and easier to audit, while naming react-dropzone saves time if your project already uses it elsewhere.

How do I get per-file progress bars instead of one overall progress bar?

Specify that each file needs its own progress state tied to its own upload call, and name the progress mechanism you're using (axios onUploadProgress, fetch with a ReadableStream, or XMLHttpRequest). Leaving this unspecified is the most common reason generated components default to a single shared progress value.

Which Cuelara tool can help me catch edge cases this prompt might miss?

Prompt Debugger — run this prompt through it before using it to surface missing constraints like concurrent upload limits, duplicate file handling, or what happens on a dropped non-file drag event (like dragging a browser tab).

Found this prompt useful? Share it.

Share

More in React Prompt Recipes

React Prompt Recipes

AI Prompt to Build a React Billing Dashboard Component Using Stripe's MCP Server

This prompt is for frontend developers who need to build a React billing dashboard component that shows a customer's live subscription, invo…

ROLE:
You are a senior React/TypeScript developer building a billing dashboard component for a SaaS product.

CONTEXT:
The component should display billing data for a customer, retrieved via Stripe's MCP server: [LIST_DATA_NEEDED_E.G._SUBSCRIPTION_PLAN_NEXT_CHARGE_DATE_PAYMENT_METHOD_RECENT_INVOICES]
Framework/styling: [REACT_VERSION_AND_STYLING_APPROACH_E.G._TAILWIND_CSS_MODULES]

CONSTRAINTS:
- Handle these billing states explicitly: [LIST_STATES_E.G._ACTIVE_PAST_DUE_CANCELED_PENDING_NO_PAYMENT_METHOD]
- Show a loading skeleton while data is being fetched, and a clear error state if the fetch fails
- Format currency and dates using the customer's actual locale/currency, not a hardcoded format
- Separate the data-fetching hook from the presentational component

OUTPUT FORMAT:
1. A short explanation of the component's structure (hook + presentational component)
2. The full TypeScript code, in a single fenced code block, with comments marking where each billing state is handled
3. A one-line note on any assumption you made about the data shape returned by the MCP server

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Dark Mode Toggle with System Preference Detection

A React dark mode toggle prompt asks ChatGPT, Claude, or Gemini to generate a theme switching component that respects the user's OS level li…

Role: You are a senior React developer building a reusable UI component.

Context:
Framework/setup: [REACT VERSION, e.g. React 18 with Vite, Next.js App Router]
Styling approach: [CSS variables / Tailwind CSS dark class / CSS-in-JS library]
Component location/usage: [where the toggle will live, e.g. app header, settings page]

Task:
Build a dark mode toggle component with this exact behavior:
1. On first load, detect the user's OS preference via the `prefers-color-scheme` media query and use it as the initial theme, applied before the main content paints (no flash of the wrong theme).
2. If the user has previously made an explicit choice, that stored choice overrides the OS preference on future visits.
3. Persist the user's explicit choice in [STORAGE MECHANISM, e.g. localStorage].
4. Listen for theme changes made in other open tabs and update this tab's theme to match.
5. Expose the current theme and a toggle function via [CONTEXT/HOOK NAME, e.g. a useTheme hook] so other components can read and react to it.

Constraints:
- Use [STYLING APPROACH] to apply the theme, not inline style objects
- Include accessible labeling (aria-label or visible text) that reflects the current state
- Keep the component dependency-free unless [ALLOWED LIBRARIES] are specified

Output format:
Return the full component code in a fenced code block, followed by a short usage example showing how to wrap the app and consume the hook elsewhere.

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Kanban Board With Drag-and-Drop

This prompt gives ChatGPT, Claude, or Gemini a complete specification for building a React Kanban board with drag and drop column reordering…

You are a senior React developer specializing in accessible, production-ready UI components.

Context:
- Framework: [REACT VERSION, e.g. React 18 with TypeScript]
- Drag-and-drop library: [LIBRARY NAME, e.g. @dnd-kit/core]
- Styling approach: [e.g. Tailwind CSS, CSS Modules, styled-components]
- Columns or workflow stages: [LIST OF COLUMN NAMES, e.g. Backlog, In Progress, Review, Done]
- State source: [e.g. local state, Zustand store, REST API endpoint]

Build a Kanban board component with the following requirements:
1. Render one column per workflow stage listed above, each showing its card count
2. Support dragging cards between columns and reordering cards within a column
3. Support keyboard-based reordering, not mouse-only interaction, for accessibility
4. Identify cards by a stable [ID FIELD NAME] field, never by array index
5. Call a [CALLBACK NAME] function on every successful move, passing the card id, source column, destination column, and new index
6. Show an optimistic UI update immediately, then roll back if [CALLBACK NAME] rejects
7. Handle empty columns and drops outside any valid column gracefully

Output format:
- The main board component
- Column and Card subcomponents
- Any custom hooks used for drag state
- A short usage example showing how to wire [CALLBACK NAME] to a real API call
- Brief notes on any library-specific setup required, such as providers, context, or CSS imports

Make this prompt yours