Introduction
Customizable React component for seamless image upload, deletion, and preview.

The PictureSelector component is a highly customizable React component designed for seamless image upload, deletion, and preview functionality, ideal for profile pictures or general image management.
๐ Feature Rich
Drag & drop, progress indicators, preview modals, and API integration
๐จ Highly Customizable
Colors, sizes, shapes, and full CSS class control
๐งช Test Mode
Simulate uploads and deletions without API dependencies
โก Performance Optimized
Smooth animations with requestAnimationFrame and abort controllers
Features
- Smooth Image Upload: Upload images with a progress ring (for profiles) or percentage display, powered by
requestAnimationFramefor smooth animations and low CPU usage. - Flexible Image Deletion: Delete images via API with customizable HTTP methods, headers, and request body, or simulated deletion in test mode.
- Progress Indicator: Displays a progress ring for circular profiles or a percentage-based indicator, with non-linear fallback for servers without
Content-Length. - Drag and Drop Support: Allows users to drag and drop images with visual feedback, with prevention of dragging selected photos for better UX.
- Image Preview: Clickable modal preview for uploaded images, supporting circular and rectangular formats.
- Full API Response Access: Provides the full API response body as an optional parameter in
onChangeImagefor advanced use cases. - Configurable Styling: Customize colors, sizes, shapes, and additional CSS classes for full control over appearance.
- Abort Controller: Cancel ongoing uploads using
AbortControllerfor better user control. - Event Callbacks: Support for
onUploadSuccess,onUploadError,onDeleteStart, andonDeleteSuccesscallbacks to handle upload and deletion events. - Test Mode: Simulate uploads and deletions with configurable delays, ideal for testing without API dependencies.
- Responsive Design: Supports RTL layouts, responsive sizing, and both circular (profile) and rectangular image types.
- Robust Error Handling: Displays clear error messages for failed operations, with proper cleanup to prevent resource leaks.
- Performance Optimizations: Prevents race conditions, ensures clean percentage displays, and optimizes resource usage using
useMemoanduseCallback.
Quick Start
import PictureSelector from "react-picture-selector";
const App = () => {
const handleImageChange = (imageUrl: string, responseData?: any) => {
console.log("New image URL:", imageUrl);
};
return (
<PictureSelector
imageUrl="https://example.com/avatar.jpg"
onChangeImage={handleImageChange}
type="profile"
title="Profile Picture"
size={180}
/>
);
};โโ