The simple files uploader applied Render Props pattern. This approach allows you to fully control UI component and behaviours.
npm install react-files-uploading
The simple files uploader applied Render Props pattern. (You can read more about this pattern here).
This approach allows you to fully control UI component and behaviours.
_This is a modified version of react-images-uploading for files uploading._
 !Github_Actions      


- Installation
- Usage
- Props
- Note
- Exported options
- Contributors ✨
npm
``bash`
npm install --save react-files-uploading
yarn
`bash`
yarn add react-files-uploading
Basic
`tsx
import * as React from 'react';
import FileUploading from 'react-files-uploading';
export const App = () => {
const [files, setFiles] = React.useState
const onChange = (fileList: File[]) => {
setFiles(fileList);
};
return (
id="btn-upload"
type="button"
style={isDragging ? { color: 'red' } : undefined}
onClick={onFileUpload}
{...dragProps}
>
Click or Drop here
} className="file-item">
{file.name}
id={update_${index}}
type="button"
onClick={() => onFileUpdate(index)}
>
{Update ${index}}
id={remove_${index}}
type="button"
onClick={() => onFileRemove(index)}
>
{Remove ${index}}
Validation
`ts
...
{({ fileList, onFileUpload, onFileRemoveAll, errors }) => (
errors &&
{errors.maxNumber && Number of selected files exceed maxNumber}
{errors.acceptType && Your selected file type is not allow}
{errors.maxFileSize && Selected file size exceed maxFileSize}
)}
...
`Drag and Drop
`tsx
...
{({ fileList, dragProps, isDragging }) => (
{isDragging ? "Drop here please" : "Upload space"}
{fileList.map((file, index) => (
{file.name}
))}
)}
...
`Props
| parameter | type | options | default | description |
| ----------- | ----------------------------------- | ---------------------------------- | ------- | ---------------------------------------------------- |
| value | array | | [] | List of files |
| onChange | function | (fileList, addUpdateIndex) => void | | Called when add, update or delete action is called |
| multiple | boolean | | false | Set
true for multiple chooses |
| maxNumber | number | | 1000 | Number of files user can select if mode = multiple |
| onError | function | (errors, files) => void | | Called when it has errors |
| acceptType | array | ['mp4', 'webm', 'png', 'pdf] | [] | The file extension(s) to upload |
| maxFileSize | number | | | Max file size (Byte) and it is used in validation |
| inputProps | React.HTMLProps\ | | | |Exported options
| parameter | type | description |
| :-------------- | :---------------------------------------- | :------------------------------------------------------------------ |
| fileList | array | List of files to render. |
| onFileUpload | function | Called when an element is clicks and triggers to open a file dialog |
| onFileRemoveAll | function | Called when removing all files |
| onFileUpdate | (updateIndex: number) => void | Called when updating a file at
updateIndex`. |Thanks goes to these wonderful people (emoji key):
vutoan266 💻 🤔 📖 🚧 ⚠️ 👀 | David Nguyen 💻 🤔 📖 👀 | DK 💻 🚇 🤔 👀 📖 | Isaac Maseruka 💻 | Vu Nguyen 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!