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.9 KiB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Starting with version 7.0.0, the `{preview}` property generation on the [File](https://developer.mozilla.org/en-US/docs/Web/API/File) objects and the `{disablePreview}` property on the `<Dropzone>` have been removed.
  2. If you need need the `{preview}`, it can be easily achieved in the `onDrop()` callback:
  3. ```jsx harmony
  4. import React, {useEffect, useState} from 'react';
  5. import {useDropzone} from 'react-dropzone';
  6. const thumbsContainer = {
  7. display: 'flex',
  8. flexDirection: 'row',
  9. flexWrap: 'wrap',
  10. marginTop: 16
  11. };
  12. const thumb = {
  13. display: 'inline-flex',
  14. borderRadius: 2,
  15. border: '1px solid #eaeaea',
  16. marginBottom: 8,
  17. marginRight: 8,
  18. width: 100,
  19. height: 100,
  20. padding: 4,
  21. boxSizing: 'border-box'
  22. };
  23. const thumbInner = {
  24. display: 'flex',
  25. minWidth: 0,
  26. overflow: 'hidden'
  27. };
  28. const img = {
  29. display: 'block',
  30. width: 'auto',
  31. height: '100%'
  32. };
  33. function Previews(props) {
  34. const [files, setFiles] = useState([]);
  35. const {getRootProps, getInputProps} = useDropzone({
  36. accept: 'image/*',
  37. onDrop: acceptedFiles => {
  38. setFiles(acceptedFiles.map(file => Object.assign(file, {
  39. preview: URL.createObjectURL(file)
  40. })));
  41. }
  42. });
  43. const thumbs = files.map(file => (
  44. <div style={thumb} key={file.name}>
  45. <div style={thumbInner}>
  46. <img
  47. src={file.preview}
  48. style={img}
  49. />
  50. </div>
  51. </div>
  52. ));
  53. useEffect(() => () => {
  54. // Make sure to revoke the data uris to avoid memory leaks
  55. files.forEach(file => URL.revokeObjectURL(file.preview));
  56. }, [files]);
  57. return (
  58. <section className="container">
  59. <div {...getRootProps({className: 'dropzone'})}>
  60. <input {...getInputProps()} />
  61. <p>Drag 'n' drop some files here, or click to select files</p>
  62. </div>
  63. <aside style={thumbsContainer}>
  64. {thumbs}
  65. </aside>
  66. </section>
  67. );
  68. }
  69. <Previews />
  70. ```