Skip to content

Instantly share code, notes, and snippets.

@tofusoup429
Created August 8, 2021 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tofusoup429/e2fb7cc0d8dbfbdab3875bef3ad54c5b to your computer and use it in GitHub Desktop.
Save tofusoup429/e2fb7cc0d8dbfbdab3875bef3ad54c5b to your computer and use it in GitHub Desktop.
import { useEffect } from "react";
import { useDropzone } from "@tofusoup429/dropzone";
const SimpleDropzone = () => {
let {fileName, dndStatus, fileContent, fileSize, initializeStates} = useDropzone("DNDTargetElement");
useEffect(()=>{
if(dndStatus === 'drop'){
console.log(fileContent);
console.log(fileSize); // fileSize may be useful when you want to put restriction on the max size of acceptable file
//do whatever you want with the fileContent
initializeStates()
}
}, [fileContent])
return(
<div style={{margin:'5%'}}>
<h5>SimpleDropzone</h5>
<div
id="DNDTargetElement" // The id should be the same as the parameter of the useDropzone.
style={{width:'100px', height:'100px', backgroundColor:(dndStatus==="dragover")?"lightgrey":"white", borderStyle:"dotted"}}
/>
</div>
)
}
export default SimpleDropzone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment