April 5, 2022 07:30 pm GMT
Original Link: https://dev.to/cuadroscode/drag-and-drop-bj1
Drag and Drop in React
In this example it was created whit React and typescript
- Drag and drop area
<div onDrop={handleDrop} onDragOver={handleDragOver} onDragEnter={handleDragEnter} onDragLeave={handleDragLeave}></div>
- Actions
const handleDragOver = ( e: DragEvent<HTMLDivElement>) => { e.preventDefault(); e.stopPropagation(); }; const handleDragEnter = ( e: DragEvent<HTMLDivElement>) => { e.preventDefault(); e.stopPropagation(); }; const handleDragLeave = ( e: DragEvent<HTMLDivElement>) => { e.preventDefault(); e.stopPropagation(); }; const handleDrop = ( e: DragEvent<any>) => { e.preventDefault(); e.stopPropagation(); // the 'files' constant contains the documents const files = e.dataTransfer.files; };
Original Link: https://dev.to/cuadroscode/drag-and-drop-bj1
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To