मुख्य सामग्री पर जाएं

माइग्रेशन गाइड

अन्य लोकप्रिय अपलोड लाइब्रेरीज़ से Dropup में कैसे माइग्रेट करें।

react-dropzone से

react-dropzone एक लोकप्रिय drag-and-drop लाइब्रेरी है। Dropup बिल्ट-इन अपलोड सपोर्ट के साथ समान कार्यक्षमता प्रदान करता है।

पहले (react-dropzone)

import { useDropzone } from 'react-dropzone';

function OldUploader() {
const [files, setFiles] = useState([]);

const { getRootProps, getInputProps, isDragActive } = useDropzone({
accept: { 'image/*': [] },
maxSize: 10485760,
onDrop: (acceptedFiles) => {
setFiles(acceptedFiles.map(file => ({
...file,
preview: URL.createObjectURL(file),
})));
},
});

const handleUpload = async () => {
for (const file of files) {
const formData = new FormData();
formData.append('file', file);
await fetch('/api/upload', {
method: 'POST',
body: formData,
});
}
};

return (
<div {...getRootProps()}>
<input {...getInputProps()} />
{isDragActive ? <p>यहाँ ड्रॉप करें</p> : <p>यहाँ फ़ाइलें खींचें</p>}
</div>
);
}

बाद में (Dropup)

import { useDropup } from '@samithahansaka/dropup';

function NewUploader() {
const { files, actions, state, getDropProps, getInputProps } = useDropup({
accept: 'image/*',
maxSize: 10 * 1024 * 1024,
upload: { url: '/api/upload' }, // बिल्ट-इन अपलोड!
});

return (
<div {...getDropProps()}>
<input {...getInputProps()} />
{state.isDragging ? <p>यहाँ ड्रॉप करें</p> : <p>यहाँ फ़ाइलें खींचें</p>}

{files.map(file => (
<div key={file.id}>
{file.preview && <img src={file.preview} />}
<span>{file.progress}%</span>
</div>
))}

<button onClick={() => actions.upload()}>अपलोड करें</button>
</div>
);
}

मुख्य अंतर

react-dropzoneDropup
getRootProps()getDropProps()
isDragActivestate.isDragging
accept: { 'image/*': [] }accept: 'image/*'
अपलोड सपोर्ट नहींप्रगति के साथ बिल्ट-इन अपलोड
मैनुअल प्रीव्यू क्लीनअपस्वचालित क्लीनअप

react-uploady से

react-uploady कई कंपोनेंट्स के साथ एक फीचर-रिच अपलोड लाइब्रेरी है।

पहले (react-uploady)

import Uploady, { useItemProgressListener, useUploady } from '@rpldy/uploady';
import UploadDropZone from '@rpldy/upload-drop-zone';

function OldApp() {
return (
<Uploady destination={{ url: '/api/upload' }}>
<UploadDropZone onDragOverClassName="drag-over">
<div>यहाँ फ़ाइलें ड्रॉप करें</div>
</UploadDropZone>
<UploadProgress />
</Uploady>
);
}

function UploadProgress() {
useItemProgressListener((item) => {
console.log(`${item.file.name}: ${item.completed}%`);
});

const { processPending } = useUploady();

return <button onClick={processPending}>अपलोड करें</button>;
}

बाद में (Dropup)

import { useDropup } from '@samithahansaka/dropup';

function NewApp() {
const { files, actions, getDropProps, getInputProps } = useDropup({
upload: { url: '/api/upload' },
onUploadProgress: (file, progress) => {
console.log(`${file.name}: ${progress}%`);
},
});

return (
<div {...getDropProps()}>
<input {...getInputProps()} />
<div>यहाँ फ़ाइलें ड्रॉप करें</div>

{files.map(file => (
<div key={file.id}>
{file.name}: {file.progress}%
</div>
))}

<button onClick={() => actions.upload()}>अपलोड करें</button>
</div>
);
}

मुख्य अंतर

react-uploadyDropup
Provider + Componentsसिंगल hook
useItemProgressListeneronUploadProgress callback
processPending()actions.upload()
कई packagesऑल-इन-वन

react-dropzone-uploader से

react-dropzone-uploader dropzone को अपलोड कार्यक्षमता के साथ जोड़ता है।

पहले (react-dropzone-uploader)

import Dropzone from 'react-dropzone-uploader';
import 'react-dropzone-uploader/dist/styles.css';

function OldUploader() {
const getUploadParams = () => ({ url: '/api/upload' });

const handleChangeStatus = ({ meta, file }, status) => {
console.log(status, meta, file);
};

return (
<Dropzone
getUploadParams={getUploadParams}
onChangeStatus={handleChangeStatus}
accept="image/*"
maxSizeBytes={10485760}
/>
);
}

बाद में (Dropup)

import { useDropup } from '@samithahansaka/dropup';

function NewUploader() {
const { files, getDropProps, getInputProps } = useDropup({
accept: 'image/*',
maxSize: 10 * 1024 * 1024,
upload: { url: '/api/upload' },
autoUpload: true,

onUploadStart: (file) => console.log('अपलोड हो रहा है', file),
onUploadComplete: (file) => console.log('पूर्ण', file),
onUploadError: (file, err) => console.log('त्रुटि', file, err),
});

return (
<div {...getDropProps()}>
<input {...getInputProps()} />
{/* आपका कस्टम UI */}
</div>
);
}

मुख्य अंतर

react-dropzone-uploaderDropup
बिल्ट-इन UI के साथ कंपोनेंटHeadless (अपना UI लाएं)
getUploadParamsupload विकल्प
onChangeStatusविशिष्ट callbacks
CSS import आवश्यककोई styles नहीं

Uppy से

Uppy एक फुल-फीचर्ड अपलोड टूलकिट है।

पहले (Uppy)

import Uppy from '@uppy/core';
import Dashboard from '@uppy/dashboard';
import XHRUpload from '@uppy/xhr-upload';
import '@uppy/core/dist/style.css';
import '@uppy/dashboard/dist/style.css';

const uppy = new Uppy()
.use(Dashboard, { inline: true, target: '#uppy' })
.use(XHRUpload, { endpoint: '/api/upload' });

uppy.on('upload-success', (file, response) => {
console.log('सफलता:', file, response);
});

function OldUploader() {
return <div id="uppy" />;
}

बाद में (Dropup)

import { useDropup } from '@samithahansaka/dropup';

function NewUploader() {
const { files, actions, state, getDropProps, getInputProps } = useDropup({
upload: { url: '/api/upload' },
onUploadComplete: (file, response) => {
console.log('सफलता:', file, response);
},
});

return (
<div>
<div {...getDropProps()}>
<input {...getInputProps()} />
यहाँ फ़ाइलें ड्रॉप करें
</div>

{files.map(file => (
<div key={file.id}>
{file.preview && <img src={file.preview} />}
<span>{file.name}</span>
<span>{file.progress}%</span>
</div>
))}

<button onClick={() => actions.upload()}>अपलोड करें</button>
</div>
);
}

मुख्य अंतर

UppyDropup
पूर्ण UI शामिलHeadless
Plugin सिस्टमऑल-इन-वन
बड़ा bundle< 10KB
Imperative APIReact hooks

सामान्य माइग्रेशन चरण

1. Dropup इंस्टॉल करें

npm uninstall react-dropzone react-uploady @rpldy/uploady  # पुराना हटाएं
npm install @samithahansaka/dropup

2. Imports अपडेट करें

// पहले
import { useDropzone } from 'react-dropzone';

// बाद में
import { useDropup } from '@samithahansaka/dropup';

3. Hook उपयोग अपडेट करें

// पहले
const { getRootProps, getInputProps, isDragActive } = useDropzone({...});

// बाद में
const { getDropProps, getInputProps, state } = useDropup({...});
// isDragActive के बजाय state.isDragging का उपयोग करें

4. Upload Config जोड़ें

// Dropup में अपलोड कार्यक्षमता शामिल है
useDropup({
upload: { url: '/api/upload' },
});

5. Event Handlers अपडेट करें

// पहले (react-dropzone)
onDrop: (files) => {...}

// बाद में (Dropup)
onFilesAdded: (files) => {...}
onUploadComplete: (file) => {...}

6. टेम्पलेट अपडेट करें

// पहले
<div {...getRootProps()}>
<input {...getInputProps()} />
</div>

// बाद में
<div {...getDropProps()}>
<input {...getInputProps()} />
</div>

फीचर तुलना

फीचरreact-dropzonereact-uploadyUppyDropup
Drag & Drop
Upload
Progress
Chunked
tus
Cloud (S3)
React Native
Bundle Size~10KB~30KB~100KB+<10KB
TypeScript
Headlessआंशिक