1.0.0 • Published 4 years ago
react-use-files v1.0.0
React-Use-File
Simple way to manage your file states
Contents
Example
const fileComponent = () => {
const useFileConfig = {
allowedExtensions: ["jpg", "png"],
maxSizeFile: 9776799,
};
const { files, handleChange, resetState, errors } = useFile(useFileConfig);
return (
<>
<input
name={"name"}
type="file"
onChange={handleChange}
multiple={true}
/>
<button onClick={() => resetState()}>erase</button>
</>
}
Installation
- All the
code
required to get started - Images of what it should look like
Setup
install npm and bower packages
$ npm install react-use-files
Features
Usage
Configuration props
Prop | Type | Description |
---|---|---|
allowedExtensions | String | Allowed Extensions |
maxSizeFile | Integer | Max Size allowed per file in KB |
useFile hook
const { files, handleChange, resetState, errors } =
useFile(configuration);
Files : array
State with the files.
handleChange: (<htmlFormEvent>) => void
Input file change event handler. This will update the files state
resetState: () => void
This will erase all the data inside files state
erros:array
State with the files errors
License
1.0.0
4 years ago