Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/oakfang/comp-up

Minimal, yet sane, file handling solution for ReactJS
https://github.com/oakfang/comp-up

Last synced: 6 days ago
JSON representation

Minimal, yet sane, file handling solution for ReactJS

Awesome Lists containing this project

README

        

# comp-up

The minimal, yet sane, way to handle files with ReactJS

## Why, though?

Handling files with React is not always great.
You have to go through the same "hide-the-input" routine, keep some state, sync the values, etc. Or you can opt for the huge chunky 3rd-party uploader that does everything for you, but you have to bend and shpe it for a while before it resembles what you actually want.

These utilities are simple abstractions with little to no design implications.

## How, though?

Well, a simple use-case would be something like this:

```jsx
import React, { useEffect } from 'react';
import axios from 'axios';
import { FileUploader, FileProvider, useFileList } from 'comp-up';

function UploadImagesPage() {
return (

Upload image files here:






);
}

function UploadImages() {
const [files, clearFiles] = useFileList();
useEffect(() => {
if (files.length) {
const data = new FormData();
data.append('files', files);
axios.post('/upload', data).then(() => {
clearFiles();
});
}
}, [files]);
return (

Pick files

);
}
```

See further example in the `example` directory.

### Caveats

- You can't use a `` inside of the ``. This is due to some arcane event rules. Please, for the sake of a11y, make sure to add `role=button` to the "button-ish" you do add.