Simple react hook to open browser file selector.
npm i use-file-picker
https://codesandbox.io/s/pedantic-joliot-8nkn7?file=/src/App.js
import { useFilePicker } from 'use-file-picker';
function App() {
const [filesContent, errors, openFileSelector, loading] = useFilePicker({
multiple: true,
// 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>
);
}
👤 Milosz Jankiewicz
👤 Kamil Planer
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Author: Jaaneek
Demo: https://codesandbox.io/s/pedantic-joliot-8nkn7?file=/src/App.js
Source Code: https://github.com/Jaaneek/useFilePicker
#react #reactjs #javascript