0.0.6 • Published 2 years ago

@zih0/use-file-drop v0.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

use-file-drop

A simple hook for drag and drop file in react.

NPM JavaScript Style Guide

Installation

$ yarn add @zih0/use-file-drop

or, with npm:

npm install @zih0/use-file-drop

Usage

import React, { useEffect } from 'react';
import useFileDrop from '@zih0/use-file-drop';

const App () => {
  const { inputRef, labelRef, files, isDragActive } = useFileDrop();

  return (
    <div>
      <input ref={inputRef} id="upload" />
      <label ref={labelRef} htmlFor="upload">
        {isDragActive ? <span>Drop the file!</span> : <span>Drag and drop the file.</span>}
      </label>
    </div>
  )
};

Options

You can set input file attributes by options:

const { inputRef, files } = useFileDrop({ multiple: true, accept: 'image/*' });

License

MIT © Zih0

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago