A react hook for the file reader api
npm install react-use-file-readerThis is a React hook to use the FileReader api.
``javascript
export const MyComponent = prop => {
const [{ result, error, loading }, setFile] = useFileReader({
method: 'readAsDataURL',
})
const onInputFile = e => {
setFile(e.target.files[0])
}
return (
<>
{loading ?
Reading file
: null}{error.message}
: null}method [String] - This is the read method you would use like: _readAsText_ _readAsDataURL_. readAsText is the default.
onload [Function] - This fire onload event of the reader. This parameter is the result of the file reader.