
If we check our application, we will just see the following text. Drag 'n' drop some files here, or click to select files In the input element, pass the input properties by calling the getInputProps() function, and spreading the properties into the element.

In the root element, pass the root properties by calling the getRootProps() function, and spreading the properties into the element. The root element can be any element you want. We will need a root element and an input element. We now have everything we need to create the dropzone component. isDragRegect - boolean, true if a file is dragged over the dropzone area and not included in acceptable file types.isDragAccept - boolean, true if a file is dragged over the dropzone area and included in acceptable file types.isDragActive - boolean, true if a file is dragged over the dropzone area.getInputProps() - a function that returns an object of the properties needed on the input element.getRootProps() - a function that returns an object of the properties needed on the root element.But, it can be used whenever you want to build a dropzone for any kind of file input as well.įor this example, we will need the following: In this example, we will use React Dropzone to create a CSV file importer. Basically, it is a React hook that makes it easy to create a drag-n-drop zone rather than building one from scratch.

React Dropzone is a “Simple React hook to create a HTML5-compliant drag’n’drop zone for files.” It has over 1.3 million weekly downloads on npm.
#React dropzone how to#
And this example will be created from a create-react-app starter application.īy the end of this article, you should have an understanding of how to do the following: This article will assume you have a basic knowledge of React. In this first article, we will take a look at the React Dropzone package and use it to build a drag-n-drop zone for files in a React application.
#React dropzone series#
This will be a three-part series where we will take a look at how to do the following:

In this series of articles, we will take a look at how to create a CSV file importer in React.
