1

I am trying to make an upload button to upload image. Before submitting, I want to display the image as soon as it is selected.

I am using material-ui library for react. Below is what I have tried, but as soon as I select a new image, the image element get destroyed from DOM.

constructor(props){
    super(props);
    this.state={
        newImage:'https://seeklogo.com/images/I/instagram-new-2016-logo-4773FE3F99-seeklogo.com.png',
    }
}

. . .

<Avatar
   alt="Selected Image"
   src={this.state.newImage}
   className={classes.bigAvatar}
/>
<RaisedButton
   <input 
      type="file" 
      onChange = {(event,newValue) => this.setState({newImage:newValue})} 
   />
</RaisedButton>
sns
  • 221
  • 4
  • 17
  • 1
    Found the answer to this here : https://stackoverflow.com/questions/43992427/how-to-display-a-image-selected-from-input-type-file-in-reactjs – sns Jul 07 '18 at 19:45

0 Answers0