🚀. Socket Launch Week Day 3:Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions.Learn more
Sign In

easy-file-drop

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-file-drop

Simplifies file drag and drop in react apps

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
3
-25%
Maintainers
1
Weekly downloads
 
Created
Source

React useFileDrop Hooks

  • Simplifies file drag and drop in react

The Hook

    const { element, dragging } = useFileDrop(onFiles)
 1. Here element is a ref, it should be attached to the element where the file will be dropped.
 2. dragging is a boolean state | it is {true} while file is being dragged
 3. onFile is a callback | (files:Array<File>)=>void | it will be triggered when even files are dropped on the attached element.

Demo

See Demo on Sandbox

App.js

import useFileDrop from 'easy-file-drop';
import { useCallback,  useState } from 'react';

function App() {
  const [files,setFiles] = useState([])
  const onFiles  = useCallback(async(files)=>{
   /** Do somethinng with the files here */
    setFiles(files)
  }, [])

  const { element, dragging } = useFileDrop(onFiles)
  return (
    <div className="App" ref={element}>
      <header className="App-header">
        <ul>
          {files.map(file=><li key={file.name}>{file.name}</li>)}
        </ul>
        {dragging?'Drop this file here':'Drag a file'}     
      </header>
    </div>
  );
}

export default App;

Keywords

drag

FAQs

Package last updated on 10 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts