Created
August 8, 2021 02:59
-
-
Save tofusoup429/e2fb7cc0d8dbfbdab3875bef3ad54c5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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