Skip to content

Instantly share code, notes, and snippets.

@rhostem
Last active October 11, 2018 08:18
Show Gist options
  • Save rhostem/1aec594db27d7add3dfb30a20b16b041 to your computer and use it in GitHub Desktop.
Save rhostem/1aec594db27d7add3dfb30a20b16b041 to your computer and use it in GitHub Desktop.
[react] trigger click hidden input
import React, { Component } from "react";
class AddImage extends Component {
constructor(props) {
super(props);
this.fileUpload = React.createRef();
this.showFileUpload = this.showFileUpload.bind(this);
}
showFileUpload() {
this.fileUpload.current.click();
}
render() {
return (
<div className="AddImage">
<input
type="file"
id="my_file"
accept="image/*"
style={{ display: "none" }}
ref={this.fileUpload}
/>
<input
type="image"
src="http://www.graphicssimplified.com/wp-content/uploads/2015/04/upload-cloud.png"
width="30px"
onClick={this.showFileUpload}
/>
</div>
);
}
}
export default AddImage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment