You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.8 KiB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. The `useDropzone` hook just binds the necessary handlers to create a drag 'n' drop zone.
  2. Use the `getRootProps()` fn to get the props required for drag 'n' drop and use them on any element.
  3. For click and keydown behavior, use the `getInputProps()` fn and use the returned props on an `<input>`.
  4. Furthermore, the hook supports folder drag 'n' drop by default. See [file-selector](https://github.com/react-dropzone/file-selector) for more info about supported browsers.
  5. ```jsx harmony
  6. import React from 'react';
  7. import {useDropzone} from 'react-dropzone';
  8. function Basic(props) {
  9. const {acceptedFiles, getRootProps, getInputProps} = useDropzone();
  10. const files = acceptedFiles.map(file => (
  11. <li key={file.path}>
  12. {file.path} - {file.size} bytes
  13. </li>
  14. ));
  15. return (
  16. <section className="container">
  17. <div {...getRootProps({className: 'dropzone'})}>
  18. <input {...getInputProps()} />
  19. <p>Drag 'n' drop some files here, or click to select files</p>
  20. </div>
  21. <aside>
  22. <h4>Files</h4>
  23. <ul>{files}</ul>
  24. </aside>
  25. </section>
  26. );
  27. }
  28. <Basic />
  29. ```
  30. Dropzone with `disabled` property:
  31. ```jsx harmony
  32. import React from 'react';
  33. import {useDropzone} from 'react-dropzone';
  34. function Basic(props) {
  35. const {acceptedFiles, getRootProps, getInputProps} = useDropzone({
  36. disabled: true
  37. });
  38. const files = acceptedFiles.map(file => (
  39. <li key={file.name}>
  40. {file.name} - {file.size} bytes
  41. </li>
  42. ));
  43. return (
  44. <section className="container">
  45. <div {...getRootProps({className: 'dropzone disabled'})}>
  46. <input {...getInputProps()} />
  47. <p>Drag 'n' drop some files here, or click to select files</p>
  48. </div>
  49. <aside>
  50. <h4>Files</h4>
  51. <ul>{files}</ul>
  52. </aside>
  53. </section>
  54. );
  55. }
  56. <Basic />
  57. ```