Package Exports
- use-file-drop
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (use-file-drop) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
use-file-drop
A simple, zero dependancy hook for implementing drag and drop in react.
Installation
npm install use-file-drop
Example
import React from "react";
import { useFileDrop } from "use-file-drop";
export default App() {
const [fileName, setFileName] = useState("");
const onDrop = (files) => {
setFileName(files[0].name);
}
const [canDrop, dropRef] = useFileDrop({
drop: onDrop
});
return (
<div ref={dropRef} className={canDrop ? "drag-over": ""}>
<div>{fileName}</div>
</div>
)
}It is better to wrap your the DropFunction in a useCallback. This will slightly improve performance in the case above since the React's Dispatch function (setFileName) is guaranteed to not change reference.
const onDrop = useCallback((files) => {
setFileName(files[0].name);
}, []);