Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

React js drag and drop Image with preview

$
0
0

I have this function for set my variable image and preview image:

const handleChangeImage = event => {     setPreviewImage(URL.createObjectURL(event.target.files[0]));    setImage( event.target.files[0] )}

and this one I just get the icon for dag and drop image:

<Box                                             backgroundColor="gray"          onChange={handleChangeImage}                                   >                               <PhotoOutlinedIcon         size="large"                                               /><Box><LabelImage>            Drag and Drop your Image Here</LabelImage>    <input             type="file"            style={{ display: 'none' }}            onChange={handleChangeImage}            ref={hiddenFileInput}               />                                            </Box></Box><Box>                                   <img         src={previewImage}         alt="Name Image"         width={150}    />                                          </Box>

so, I just want to do a Drag and drop image with preview, so currently it not work.

I was testing removing of input, the style display and I drag and drop one image, and preview image work, but I just want is display one icon, like:

enter image description here

so why don't work??? when I add display: 'none'


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>