Ok so I have a form that has file inputs on it for images (and it previews the image before submission) but only the first input updates (no matter which input I use to put my image up).
Here are the repro steps:
- Click "Add Question" button 2 or more times
- Click (because drop doesn't work yet) on the second dropzone and upload a file.
- See that the first dropzone updates and not the second
And here is my code for the drop zone component:
class DropZone extends Component {
constructor(props){
super(props)
this.state = {
file: "",
fileId: uuid()
}
this.handleChange = this.handleChange.bind(this)
}
handleChange(event) {
this.setState({
file: URL.createObjectURL(event.target.files[0])
})
//document.getElementsByClassName("dropZone").style.backgroundImage = 'url(' + this.state.file + ')';
}
render() {
return (
<div >
<input type="file" id="file" name="file" class="inputFile" onChange={this.handleChange}/>
<label key={uuid()} for="file" value={this.state.file} onchange={this.handleChange}>
<div class="dropZone" key={uuid()}>
Drop or Choose File
<img src={this.state.file} id="pic" name="file" accept="image/*"/>
</div>
</label>
<div>
</div>
</div>
);
}
}
I am new to React and JS so any explanation would help loads. Thanks!