| 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 |
|
| 3 |
If you need the `{preview}`, it can be easily achieved in the `onDrop()` callback: |
| 4 |
|
| 5 |
```jsx harmony |
| 6 |
import React, {useEffect, useState} from 'react'; |
| 7 |
import {useDropzone} from 'react-dropzone'; |
| 8 |
|
| 9 |
const thumbsContainer = { |
| 10 |
display: 'flex', |
| 11 |
flexDirection: 'row', |
| 12 |
flexWrap: 'wrap', |
| 13 |
marginTop: 16 |
| 14 |
}; |
| 15 |
|
| 16 |
const thumb = { |
| 17 |
display: 'inline-flex', |
| 18 |
borderRadius: 2, |
| 19 |
border: '1px solid #eaeaea', |
| 20 |
marginBottom: 8, |
| 21 |
marginRight: 8, |
| 22 |
width: 100, |
| 23 |
height: 100, |
| 24 |
padding: 4, |
| 25 |
boxSizing: 'border-box' |
| 26 |
}; |
| 27 |
|
| 28 |
const thumbInner = { |
| 29 |
display: 'flex', |
| 30 |
minWidth: 0, |
| 31 |
overflow: 'hidden' |
| 32 |
}; |
| 33 |
|
| 34 |
const img = { |
| 35 |
display: 'block', |
| 36 |
width: 'auto', |
| 37 |
height: '100%' |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
function Previews(props) { |
| 42 |
const [files, setFiles] = useState([]); |
| 43 |
const {getRootProps, getInputProps} = useDropzone({ |
| 44 |
accept: { |
| 45 |
'image/*': [] |
| 46 |
}, |
| 47 |
onDrop: acceptedFiles => { |
| 48 |
setFiles(acceptedFiles.map(file => Object.assign(file, { |
| 49 |
preview: URL.createObjectURL(file) |
| 50 |
}))); |
| 51 |
} |
| 52 |
}); |
| 53 |
|
| 54 |
const thumbs = files.map(file => ( |
| 55 |
<div style={thumb} key={file.name}> |
| 56 |
<div style={thumbInner}> |
| 57 |
<img |
| 58 |
src={file.preview} |
| 59 |
style={img} |
| 60 |
// Revoke data uri after image is loaded |
| 61 |
onLoad={() => { URL.revokeObjectURL(file.preview) }} |
| 62 |
/> |
| 63 |
</div> |
| 64 |
</div> |
| 65 |
)); |
| 66 |
|
| 67 |
useEffect(() => { |
| 68 |
// Make sure to revoke the data uris to avoid memory leaks, will run on unmount |
| 69 |
return () => files.forEach(file => URL.revokeObjectURL(file.preview)); |
| 70 |
}, [files]); |
| 71 |
|
| 72 |
return ( |
| 73 |
<section className="container"> |
| 74 |
<div {...getRootProps({className: 'dropzone'})}> |
| 75 |
<input {...getInputProps()} /> |
| 76 |
<p>Drag 'n' drop some files here, or click to select files</p> |
| 77 |
</div> |
| 78 |
<aside style={thumbsContainer}> |
| 79 |
{thumbs} |
| 80 |
</aside> |
| 81 |
</section> |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
<Previews /> |
| 86 |
``` |