Coder Social home page Coder Social logo

youngfonz / react-dropzone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from react-dropzone/react-dropzone

1.0 2.0 0.0 1.11 MB

Simple HTML5 drag-drop zone with React.js.

Home Page: https://react-dropzone.netlify.com

License: MIT License

JavaScript 100.00%

react-dropzone's Introduction

react-dropzone logo

react-dropzone

Build Status npm version codecov OpenCollective OpenCollective

Simple HTML5-compliant drag'n'drop zone for files built with React.js.

Documentation and examples: https://react-dropzone.netlify.com


Installation

Install it from npm and include it in your React build process (using Webpack, Browserify, etc).

npm install --save react-dropzone

Usage

Import Dropzone in your React component:

import Dropzone from 'react-dropzone'

and specify the onDrop method that accepts two arguments. The first argument represents the accepted files and the second argument the rejected files.

function onDrop(acceptedFiles, rejectedFiles) {
  // do stuff with files...
}

Files accepted or rejected based on accept prop. This must be a valid MIME type according to input element specification.

Please note that onDrop method will always be called regardless if dropped file was accepted or rejected. The onDropAccepted method will be called if all dropped files were accepted and the onDropRejected method will be called if any of the dropped files was rejected.

Using react-dropzone is similar to using a file form field, but instead of getting the files property from the field, you listen to the onDrop callback to handle the files. Simple explanation here: http://abandon.ie/notebook/simple-file-uploads-using-jquery-ajax

Specifying the onDrop method, provides you with an array of Files which you can then send to a server. For example, with SuperAgent as a http/ajax library:

    onDrop: acceptedFiles => {
        const req = request.post('/upload');
        acceptedFiles.forEach(file => {
            req.attach(file.name, file);
        });
        req.end(callback);
    }

PropTypes

See https://react-dropzone.netlify.com/#proptypes

Word of caution when working with previews

Important: react-dropzone doesn't manage dropped files. You need to destroy the object URL yourself whenever you don't need the preview by calling window.URL.revokeObjectURL(file.preview); to avoid memory leaks.

Support

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

License

MIT

react-dropzone's People

Contributors

okonet avatar paramaggarwal avatar anuragces avatar robmclarty avatar toshipon avatar dimitarchristoff avatar voronianski avatar nuc avatar mwolson avatar tmarshall avatar greenkeeper[bot] avatar vlindhol avatar subtirelumihail avatar maffoobristol avatar frankwallis avatar jonathanhudak avatar donavon avatar wmartins avatar tikotzky avatar pomax avatar marnusw avatar indraneel avatar idolize avatar akkie avatar appleboy avatar chrisbuttery avatar timothyjlaurent avatar timse avatar r3ifi3r avatar sijmenhuizenga avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar Alphonso Morris avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.