import React, { useCallback } from 'react'; import { useDropzone } from 'react-dropzone'; import useConnection from '../hooks/useConnection'; import FileView from '../components/File'; import FileGrid from '../components/FileGrid'; const readFile = (file: File) => new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => { resolve({ name: file.name, type: file.type, body: reader.result, }); }; reader.onerror = (err) => { reject(err); }; reader.readAsDataURL(file); }); const Connected: React.FC<{}> = () => { const { send, messages } = useConnection(); const onDrop = useCallback(async (acceptedFiles: File[]) => { const files = await Promise.all(acceptedFiles.map(readFile)); files.forEach(send); }, [send]); const { getRootProps, getInputProps, isDragActive, } = useDropzone({onDrop}) return ( <>
Drop the files here ...
):(Drag 'n' drop some files here, or click to select files!
)}