How to use the react-dropzone.useDropzone function in react-dropzone

To help you get started, we’ve selected a few react-dropzone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codefordenver / ideaLab / Frontend / src / components / Upload / components / Upload.jsx View on Github external
function Upload(props) {
  const onDrop = useCallback(acceptedFiles => {
    props.setFilename(acceptedFiles[0].name);
    props.callback(acceptedFiles);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });

  return (
    <div>
      <input>
      {isDragActive ? <p>upload or drag STL files</p> : <p>upload STL files</p>}
      {props.filename ? <p>Filename: {props.filename}</p> : null}
    </div>
  );
}
github captbaritone / webamp / modern / src / debugger / index.js View on Github external
function Wrapper() {
  const [maki, setMaki] = React.useState(null);
  const onDrop = React.useCallback(async acceptedFiles =&gt; {
    if (acceptedFiles.length !== 1) {
      alert("Only drop one file at a time");
      return;
    }
    const file = acceptedFiles[0];
    const arrayBuffer = await readFileAsArrayBuffer(file);
    setMaki(arrayBuffer);
    // Do something with the files
  }, []);
  const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
  return (
    <div style="{{">
      {maki == null ? (
        &lt;&gt;
          <h1 style="{{">
            Drop a .maki file here to debug
          </h1>
          <input type="file">
        </div>
github Swizec / modern-webapp-starter-sep-2019 / web / src / components / ImageUpload.js View on Github external
if (response.status !== 200) {
      // The upload failed, so let's notify the caller.
      setUploading(false)
      onError && onError()
      return
    }
    // Let the caller know that the upload is done, so that it can send the URL
    // to the backend again, persisting it to the database.

    setUploading(false)
    onUploadReady && onUploadReady()
  }

  return {
    ...useDropzone({
      accept: "image/*",
      disabled: typeof presignedUploadUrl !== "string",
      onDrop,
    }),
    uploading,
  }
}
github btzr-io / Villain / packages / villain-web / src / routes / reader / view.js View on Github external
setFile(url)
  })

  // Update source
  React.useEffect(() =&gt; {
    setSource(query.src || file)
  }, [file, query])

  const onDrop = React.useCallback(
    acceptedFiles =&gt; {
      handleFileChange(acceptedFiles)
    },
    [handleFileChange]
  )

  const { getRootProps, isDragActive } = useDropzone({ onDrop })

  return !source ? (
    
      <section>
        {!isDragActive ? (
          <div>
            <div>
              <b>Select</b> comic book or <b>drop</b> it here
            </div>
            <div>
              
              <button>Try example</button>
            </div>
            <div>
              <b>Enter</b> a valid url of the comic book
            </div></div></section>
github codefordenver / ideaLab / Frontend / src / components / Upload / components / Upload.jsx View on Github external
function Upload(props) {
  const onDrop = useCallback(acceptedFiles =&gt; {
    props.setFilename(acceptedFiles[0].name);
    props.callback(acceptedFiles);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });

  return (
    <div>
      <input>
      {isDragActive ? <p>upload or drag STL files</p> : <p>upload STL files</p>}
      {props.filename}
    </div>
  );
}
github AntlerVC / firetable / www / src / components / ImportCSV.tsx View on Github external
const [columnKey, setColumnKey] = useState();
  const [csvData, setCsvData] = useState([]);
  const onDrop = useCallback(async acceptedFiles =&gt; {
    const file = acceptedFiles[0];
    var reader = new FileReader();
    reader.onload = function(event: any) {
      const csvString = event.target.result;
      parse(csvString, {}, function(err, output) {
        const keys = output.shift();
        setCsvData(output);
        setCsvKeys(keys);
      });
    };
    reader.readAsText(file);
  }, []);
  const { getRootProps, getInputProps, isDragActive } = useDropzone({
    onDrop,
    multiple: false,
  });
  function handleClickOpen() {
    setOpen(true);
  }

  function handleClose() {
    setOpen(false);
    setKeyPairs([]);
    setCsvKeys([]);
    setCsvKey(null);
    setColumnKey(null);
  }
  function handleImport() {
    const newDocs = csvData.map((row: any[]) =&gt; {
github researchstudio-sat / webofneeds / webofneeds / won-owner-webapp / src / main / webapp / app / components / file-dropzone.jsx View on Github external
data: b64data,
          };
          return fileData;
        })
        .then(fileData =&gt; {
          props.onFilePicked({ file: fileData });
        });
    });
  }, []);
  const {
    getRootProps,
    getInputProps,
    isDragActive,
    isDragReject,
    isDragAccept,
  } = useDropzone({ onDrop });

  const icon = isDragReject ? "#ico36_close" : "#illu_drag_here";

  return (
    
      <div>
        </div>
github Lambda-School-Labs / designhub-fe / client / src / components / MultiImageUpload.js View on Github external
export function MultiImageUpload(props) {
  const { files, setFiles } = props;
  const {
    isDragActive,
    isDragReject,
    getRootProps,
    getInputProps
  } = useDropzone({
    accept: 'image/*',
    onDrop: acceptedFiles => {
      setFiles([
        ...files,
        ...acceptedFiles.map(file =>
          Object.assign(file, {
            preview: URL.createObjectURL(file)
          })
        )
      ]);
    }
  });

  const thumbs = () => {
    const removeThumbnail = index => {
      const newList = files.filter((file, i) => files[index] !== file);
github metrasynth / radiant-voices / examples / rv-react-ts-example / src / App.tsx View on Github external
const options = { type: "application/octet-stream" }
    const blob = new Blob(blobParts, options)
    FileSaver.saveAs(blob, filename)
  }
  const onPlayClick = () =&gt; {
    sunvox.sv_play_from_beginning(0)
  }
  const onStopClick = () =&gt; {
    sunvox.sv_stop(0)
  }
  const onProjectOptionsChange = (event: ChangeEvent) =&gt; {
    const value = event.target.value || "{}"
    setProjectOptions(value)
  }

  const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop })

  return (
    <div>
      <h1>sunvox.audio</h1>
      <h2>What is this?</h2>
      <p>
        This is an early, work-in-progress demonstration of the SunVox and Radiant
        Voices libraries for JavaScript.
      </p>
      <h3>Project loader</h3>
      <p>
        Load a SunVox project (*.sunvox file) from your computer, and it will play it
        back in SunVox and load the project in Radiant Voices:
      </p>
      <div>
        <input></div></div>
github oceanprotocol / commons / client / src / components / molecules / Dropzone.tsx View on Github external
}: {
    handleOnDrop(files: File[]): void
    disabled?: boolean
    multiple?: boolean
}) {
    const onDrop = useCallback(acceptedFiles =&gt; handleOnDrop(acceptedFiles), [
        handleOnDrop
    ])

    const {
        acceptedFiles,
        getRootProps,
        getInputProps,
        isDragActive,
        isDragReject
    } = useDropzone({ onDrop })

    const files = acceptedFiles.map((file: any) =&gt; (
        <li>
            {file.path} - {formatBytes(file.size, 0)}
        </li>
    ))

    return (
        &lt;&gt;
            {acceptedFiles.length &gt; 0 ? (
                <aside>
                    <ul>{files}</ul>
                </aside>
            ) : (

react-dropzone

Simple HTML5 drag-drop zone with React.js

MIT
Latest version published 2 years ago

Package Health Score

85 / 100
Full package analysis