import { FunctionComponent, useCallback } from "react"; import { useDropzone } from "react-dropzone"; import { DocumentDownloadIcon } from "@heroicons/react/outline"; export const FileDropzone: FunctionComponent = ({ children }) => { const onDrop = useCallback((acceptedFiles) => { acceptedFiles.forEach((file: Blob) => { const reader = new FileReader(); reader.onabort = () => console.log("file reading was aborted"); reader.onerror = () => console.log("file reading has failed"); reader.onload = () => { if (typeof reader.result === "string") { let json = JSON.parse(reader.result); // dataSourceDispatch(setJSONAction("Needs title", json)); } else { // dataSourceDispatch(setErrorAction("Can't read file")); } }; reader.readAsText(file); }); }, []); const { getRootProps, isDragActive } = useDropzone({ onDrop, multiple: false, maxFiles: 1, accept: "application/json, text/*", noDragEventsBubbling: true, }); return (
Drag 'n' drop some files here, or click to select files