Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. The hook accepts a `getFilesFromEvent` prop that enhances the handling of dropped file system objects and allows more flexible use of them e.g. passing a function that accepts drop event of a folder and resolves it to an array of files adds plug-in functionality of folders drag-and-drop.
  2. Though, note that the provided `getFilesFromEvent` fn must return a `Promise` with a list of `File` objects (or `DataTransferItem` of `{kind: 'file'}` when data cannot be accessed).
  3. Otherwise, the results will be discarded and none of the drag events callbacks will be invoked.
  4. In case you need to extend the `File` with some additional properties, you should use [Object.defineProperty()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) so that the result will still pass through our filter:
  5. ```jsx harmony
  6. import React from 'react';
  7. import {useDropzone} from 'react-dropzone';
  8. function Plugin(props) {
  9. const {acceptedFiles, getRootProps, getInputProps} = useDropzone({
  10. getFilesFromEvent: event => myCustomFileGetter(event)
  11. });
  12. const files = acceptedFiles.map(f => (
  13. <li key={f.name}>
  14. {f.name} has <strong>myProps</strong>: {f.myProp === true ? 'YES' : ''}
  15. </li>
  16. ));
  17. return (
  18. <section className="container">
  19. <div {...getRootProps({className: 'dropzone'})}>
  20. <input {...getInputProps()} />
  21. <p>Drag 'n' drop some files here, or click to select files</p>
  22. </div>
  23. <aside>
  24. <h4>Files</h4>
  25. <ul>{files}</ul>
  26. </aside>
  27. </section>
  28. );
  29. }
  30. async function myCustomFileGetter(event) {
  31. const files = [];
  32. const fileList = event.dataTransfer ? event.dataTransfer.files : event.target.files;
  33. for (var i = 0; i < fileList.length; i++) {
  34. const file = fileList.item(i);
  35. Object.defineProperty(file, 'myProp', {
  36. value: true
  37. });
  38. files.push(file);
  39. }
  40. return files;
  41. }
  42. <Plugin />
  43. ```