Skip to content

Commit

Permalink
update file drop component to work with use effect
Browse files Browse the repository at this point in the history
  • Loading branch information
memelotsqui committed Dec 10, 2023
1 parent f5e01ec commit a24ab5e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/FileDropComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import styles from './FileDropComponent.module.css';

export default function FileDropComponent ({onFilesDrop}){
const [isDragging, setIsDragging] = useState(false);
const [files, setFiles] = React.useState(null);

useEffect(() => {
const handleDrop = (event) => {
event.preventDefault();
setIsDragging(false);
const files = event.dataTransfer.files;
if (onFilesDrop) {
onFilesDrop(files);
setFiles(files)
}
};

Expand All @@ -31,6 +32,13 @@ export default function FileDropComponent ({onFilesDrop}){
};
}, []);

useEffect(()=>{
if (files){
console.log("files");
onFilesDrop(files);
}
},[files])

const handleDragLeave = () => {
setIsDragging(false);
};
Expand Down

0 comments on commit a24ab5e

Please sign in to comment.