Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import ReactDOM from 'react-dom';
- class App extends React.Component{
- constructor(props){
- super(props);
- this.input = React.createRef();
- this.fileInput = React.createRef();
- this.handleSubmit = this.handleSubmit.bind(this);
- }
- handleSubmit(e) {
- e.preventDefault();
- console.log(`submit: ${this.input.current.value}`);
- const file = this.fileInput.current.files[0];
- if(file) {
- console.log(file.name);
- console.log(file);
- }
- }
- render() {
- return (<div>
- <h1>Uncontrolled form</h1>
- <form onSubmit={this.handleSubmit}>
- <input defaultValue="Texty text" type="text" ref={this.input}/>
- <input type="file" ref={this.fileInput}/>
- <button type="submit">Submit</button>
- </form>
- </div>)
- }
- }
- ReactDOM.render(<App />, document.getElementById('root'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement