modification: gatsby-remark-code-plugin

This commit is contained in:
Vishal Raj
2017-12-21 16:33:32 +05:30
parent 4d1342506d
commit dd41d34c20
2 changed files with 27 additions and 1 deletions

View File

@@ -226,7 +226,7 @@ class FileInput extends React.Component {
}
```
[Try it on CodePen.](https://codepen.io/fetard/pen/bYvaJY?editors=0010)
[Try it on CodePen](codepen://components-and-props/input-type-file)
Note how a `ref` to the file input is used to access the file(s) in the submit handler

View File

@@ -0,0 +1,26 @@
class FileInput extends React.Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit (event) {
event.preventDefault();
alert(`Selected file - ${this.fileInput.files[0].name}`);
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<label>
Upload file:
<input type='file' ref={input => {this.fileInput = input}} />
</label>
<br/>
<button type='submit'>Submit</button>
</form>
);
}
}
ReactDOM.render(<FileInput />, document.getElementById('root'));