Skip to content

sergiopallet/react-use-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published