Skip to content

Montero359/useFilePicker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to use-file-picker 👋

Version License: MIT Twitter: twitter.com/JankiewiczMi/

Simple react hook to open browser file selector.

Install

npm i use-file-picker

Example

https://codesandbox.io/s/pedantic-joliot-8nkn7?file=/src/App.js

Usage

import { useFilePicker } from 'use-file-picker';

function App() {
  const [filesContent, errors, openFileSelector, loading] = useFilePicker({
    multiple: true,
    readAs: 'Text', // default: "Text", availible formats: "Text" | "BinaryString" | "ArrayBuffer" | "DataURL"
    // accept: '.ics,.pdf',
    accept: ['.json', '.pdf'],
  });

  if (errors.length > 0) return <p>Error!</p>;

  if (loading) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      <button onClick={() => openFileSelector()}>Reopen file selector</button>
      <pre>{JSON.stringify(filesContent)}</pre>
    </div>
  );
}

Author

👤 Milosz Jankiewicz

👤 Kamil Planer

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

About

Simple react hook to open browser file selector.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 89.0%
  • JavaScript 6.8%
  • HTML 4.2%