Answers for "react image upload preview image"

1

display preview of image upload react

//ReactJs

import {useState } from "react";

export default function Home() {
	 const [file,  setFile] = useState("")
     
     const handleChange = (e) =>{
       setFile(URL.createObjectURL(e.target.files[0]))
     }
     
     return (
         <div>
          <input type="file" onChange={handleChange}/>
          <img src={file}/>
        </div>
     )
	
}
Posted by: Guest on August-06-2021
1

how to upload image in react js

import FileBase64 from "react-file-base64";
// FileBase64 <- use as component

<FileBase64 
	type="file"
    multiple={false} <- if want to upload multiple images set "true"
    onDone={} <- take callback function
/>

// onDone return an object of: filename, fileType, base64 data
// use the setState or function of useState to grap the base64 data
Posted by: Guest on September-28-2021

Code answers related to "react image upload preview image"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language