Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flexcodelabs/use-drag-drop-hook

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flexcodelabs/use-drag-drop-hook

[![npm](https://img.shields.io/npm/v/@flexcodelabs/use-drag-drop-hook)](https://www.npmjs.com/package/@flexcodelabs/use-drag-drop-hook) [![NPM](https://img.shields.io/npm/l/@flexcodelabs/use-drag-drop-hook)](https://www.npmjs.com/package/@flexcodelabs/use

  • 0.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
3
Weekly downloads
 
Created
Source

@flexcodelabs/use-drag-drop-hook

npm NPM

Package Name

Features

  • List of features

Installation

npm install @flexcodelabs/use-drag-drop-hook

or

yarn add @flexcodelabs/use-drag-drop-hook

Usage

...
import useDragAndDrop from '@flexcodelabs/use-drag-drop-hook';

// inside React Fn
const {
  dragOver, // returns true if drag over event triggered
  setDragOver, // update drag over state
  onDragOver, // a function to be called onDrag event
  onDragLeave, // a function to be called on drag leave
  fileDropError, // returns error if there is any on file drop
  setFileDropError, // set errors especially used on validation
} = useDragAndDrop()
...
import useDragAndDrop from '@flexcodelabs/use-drag-drop-hook';

const Test = () => {
  const {
    dragOver,
    onDragOver,
    onDragLeave,
    fileDropError,
    setFileDropError,
  } = useDragAndDrop();
  const [file, setFile] = useState<any>(null);
  const onDrop = (e: any) => {
    e.preventDefault();
    if (e.dataTransfer.files[0]?.size > 10000) {
      setFileDropError("Invalid file size");
    }
    // do something with the file
    setFile(e.dataTransfer.files[0]);
  };

  return (
    <div>
      <label
        onDrag={onDragOver}
        onDragOver={onDragOver}
        onDragLeave={onDragLeave}
        onDrop={onDrop}
      >
        {file && <p>{file?.name}</p>}
        Drag and Drop your files here
        <input type="file" />
        {fileDropError && <p>{fileDropError}</p>}
        <p>{dragOver && "Drop your files here"}</p>
        <p>Max file size = 10Kb</p>
      </label>
    </div>
  );
};

Examples

Source code

FAQs

Package last updated on 31 Jul 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc