Skip to content

Commit 5d17b08

Browse files
docs(README): update README.md
1 parent bc9adb3 commit 5d17b08

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

README.md

+34-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# use-input-file
22

33
![CI](https://github.com/neighborhood999/use-input-file/workflows/CI/badge.svg)
4+
[![npm](https://flat.badgen.net/npm/v/use-input-file)](https://www.npmjs.com/package/use-input-file)
5+
[![minified + gzip](https://flat.badgen.net/bundlephobia/min/use-input-file)](https://bundlephobia.com/result?p=use-input-file)
6+
[![styled with prettier](https://flat.badgen.net/badge/style%20with/prettier/ff69b4)](https://github.com/prettier/prettier)
47

5-
A React hook that allows you to handle `<input type="file">`.
8+
A React hook that allows you to handle HTML `<input type="file">`.
69

710
## Installation
811

@@ -33,14 +36,14 @@ const App () => {
3336
## Passing Custom `ref`
3437

3538
```jsx
36-
import React, { useRef } from 'react';
39+
import React, { useEffect, useRef } from 'react';
3740

3841
const App () => {
3942
const ref = useRef(null);
4043
const { files } = useInputFile({ ref });
4144

4245
// Check your upload files
43-
React.useEffect(() => {
46+
useEffect(() => {
4447
console.log(files);
4548
}, [files]);
4649

@@ -57,13 +60,15 @@ You can set input file attributes by `options`:
5760
```jsx
5861
const options = { multiple: true, accept: 'image/*' };
5962
const { ref, files } = useInput({ options });
63+
64+
// render: <input type="file" multiple="multiple" accept="image/*">
6065
```
6166

6267
## The `onChange` Callback
6368

64-
The hook default will return empty `files`. When input file changed will return new `files`.
69+
As above, the hook default will return empty `files`, when the input file changed will return new `files` with your changed.
6570

66-
You can pass `onChange` callback argument to `hook` and handle input file change for you want.
71+
Sometimes you may want to custom onChange for your logic, so you can pass `onChange` callback argument to `hook` and handle input file change for you want.
6772

6873
```jsx
6974
const onChange = event => {
@@ -73,6 +78,30 @@ const onChange = event => {
7378
const { ref } = useInputFile({ onChange });
7479
```
7580

81+
## API
82+
83+
```js
84+
const { ref, file } = useInputFile({/* ...options */});
85+
```
86+
87+
### Hook Parameters
88+
89+
You can configure `use-input-file` via the below parameters:
90+
91+
| Key | Type | Default | Description |
92+
| -------- | --------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
93+
| ref | React.RefObject | `React.RefObject<HTMLInputElement>` | Passing your custom `ref`. |
94+
| options | object | `{ accept: string, multiple: boolean }` | Check [MDN - input type="file"](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file) for more details. |
95+
| onChange | function | | You can pass `onChange` callback argument to `hook` and handle input file change for you want. |
96+
97+
### Return Values
98+
99+
| Key | Type | Default | Description |
100+
| ----- | --------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
101+
| ref | React.RefObject | `React.RefObject` | The react `ref`. |
102+
| files | array | `[]` | The hook default will return empty [File](https://developer.mozilla.org/en-US/docs/Web/API/File), when the input file changed will return new [File](https://developer.mozilla.org/en-US/docs/Web/API/File) with your changed. |
103+
104+
76105
## Tests
77106

78107
```sh

0 commit comments

Comments
 (0)