Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3.  
  4.  
  5. class App extends React.Component{
  6.  
  7. constructor(props){
  8. super(props);
  9. this.input = React.createRef();
  10. this.fileInput = React.createRef();
  11.  
  12. this.handleSubmit = this.handleSubmit.bind(this);
  13. }
  14.  
  15.  
  16. handleSubmit(e) {
  17. e.preventDefault();
  18. console.log(`submit: ${this.input.current.value}`);
  19. const file = this.fileInput.current.files[0];
  20. if(file) {
  21. console.log(file.name);
  22. console.log(file);
  23. }
  24. }
  25.  
  26. render() {
  27. return (<div>
  28. <h1>Uncontrolled form</h1>
  29. <form onSubmit={this.handleSubmit}>
  30. <input defaultValue="Texty text" type="text" ref={this.input}/>
  31. <input type="file" ref={this.fileInput}/>
  32. <button type="submit">Submit</button>
  33. </form>
  34. </div>)
  35. }
  36. }
  37.  
  38.  
  39. ReactDOM.render(<App />, document.getElementById('root'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement