createRoot (see the React docs) and a Vite dev server for local development.
1. Entrypoint: index.js / index.jsx
Ensure your entry file mounts the app with the React 18+ API. This minimal entry file uses thecreateRoot API:
- Reference: Vite documentation
- Reference: React createRoot API
2. App.jsx — UI, upload form, and submit handler
OpenApp.jsx. We’ll create a compact form that accepts:
- A file input for an image,
- A quality slider (0–100),
- A submit button that posts the file and quality as
FormDatato your optimization API.
App.jsx implementation with state handling, uploading, and basic error handling:
Tips:
- Add
name="image"to the file input so server frameworks reliably access the uploaded file. - Provide user feedback with
loadingstate so users know the optimization is in progress.
Do not set the
Content-Type header manually when sending FormData. The browser sets the multipart boundary automatically; setting Content-Type yourself will break the request.3. Form data and server expectations
When sending the upload, we useFormData:
- Field
image: the uploaded file - Field
quality: numeric quality value (0–100)
If your backend returns:
- JSON with a result URL: parse with
await response.json()and use the URL to preview or download. - Binary image data: use
await response.blob()and create an object URL viaURL.createObjectURL(blob).
4. Styling: App.css
Apply these CSS rules to create a centered, responsive form with a dashed file input and a full-width slider:5. UX expectations
With the markup, handler, and CSS applied you now have a centered, responsive form that:- Lets the user choose an image file,
- Lets the user select an output quality with a slider (0–100),
- Posts the file and quality to your API for processing.
box-sizing: border-box rule and the input width settings should correct that.
Once the UI is in place you can:
- Change the page background and accent colors to match your brand,
- Add an inline preview for the selected file before upload,
- Show an optimized-image preview after the server responds (either via a returned URL or by creating an object URL from the returned blob).

Links and references
- React createRoot API
- Vite documentation
- FormData (MDN)
- Content-Type header (MDN)
- Response.blob() (MDN)
- URL.createObjectURL (MDN)