Datasets:
text-dataset-tiny-code-script-py-format / ysnrfd_messenger /BACKUP3 /frontend /src /hooks /useFileUpload.js
Download ysnrfd_messenger/BACKUP3/frontend/src/hooks/useFileUpload.js from ysn-rfd/text-dataset-tiny-code-script-py-format: direct link, hf CLI and curl.
- Browser
- Download file 978 Bytes
-
https://huggingface.co/datasets/ysn-rfd/text-dataset-tiny-code-script-py-format/resolve/main/ysnrfd_messenger/BACKUP3/frontend/src/hooks/useFileUpload.js
- Command line
-
hf download hf://datasets/ysn-rfd/text-dataset-tiny-code-script-py-format/ysnrfd_messenger/BACKUP3/frontend/src/hooks/useFileUpload.js
-
curl -L -o useFileUpload.js https://huggingface.co/datasets/ysn-rfd/text-dataset-tiny-code-script-py-format/resolve/main/ysnrfd_messenger/BACKUP3/frontend/src/hooks/useFileUpload.js
978 Bytes
| import { useState, useCallback } from 'react'; | |
| import { uploadService } from '../services/api'; | |
| export const useFileUpload = () => { | |
| const [uploading, setUploading] = useState(false); | |
| const [progress, setProgress] = useState(0); | |
| const [error, setError] = useState(null); | |
| const uploadFile = useCallback(async (file) => { | |
| try { | |
| setUploading(true); | |
| setProgress(0); | |
| setError(null); | |
| const response = await uploadService.uploadFile(file, (progress) => { | |
| setProgress(progress); | |
| }); | |
| setUploading(false); | |
| setProgress(100); | |
| return response; | |
| } catch (error) { | |
| setError(error.error || 'File upload failed'); | |
| setUploading(false); | |
| throw error; | |
| } | |
| }, []); | |
| const reset = useCallback(() => { | |
| setUploading(false); | |
| setProgress(0); | |
| setError(null); | |
| }, []); | |
| return { | |
| uploadFile, | |
| uploading, | |
| progress, | |
| error, | |
| reset | |
| }; | |
| }; |