React Uploader Hook
React Uploader Hook is a hook simply for file upload
It can be used with react-dropzone
or a simple <input type="file"/>
The key is calling the onDrop(files)
with FileList
or an array of File
Install
// npmnpm install react-uploader-hook // or yarnyarn add react-uploader-hook
Usage
;; ;
Functions and parameters
useFileUploader()
takes in an object of type FileUploaderProps
as an argument
getUploadParams()
This is a callback function that will be called before a request is sent to the server to upload each file. The function must return an object in the following shape
onUploaded()
This function will be called on successful upload of each file. The first argument will be fileBag
, a wrapper object for the uploaded file
the status field will contain the value 'uploaded'
and 'progress'
100. The second argument will be an array of all uploaded fileBags
onFailed()
Similar to onUploaded(), however the status will be 'failed'
. Then httpStatus
and responseData
would
contain additional information to know why the upload failed. The second argument will be an array of all failed fileBags
onDrop()
Call this function to trigger an upload. It accepts File[] or FileList as argument
retryUpload()
Call this function to retry a failed upload. It accepts the fileBag id as argument