Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Abdusamadzoda Abdulaziz
Added: Jul 14, 2020 1:32 PM
Views: 7
Tags: no tags
  1. import React from "react";
  2.  
  3. class App extends React.Component {
  4.     constructor(props) {
  5.       super(props)
  6.       this.state = { username: '' }
  7.       this.handleChange = this.handleChange.bind(this)
  8.       this.onFormSubmit = this.onFormSubmit.bind(this)
  9.     }
  10.  
  11.     handleChange(event) {
  12.       this.setState({ username: event.target.value })
  13.     }
  14.  
  15.     onFormSubmit(event){
  16.         event.preventDefault();
  17.  
  18.         console.log(this.state.username)
  19.     }
  20.  
  21.     render() {
  22.       return (
  23.         <form onSubmit={this.onFormSubmit}>
  24.           <input
  25.             type="text"
  26.             value={this.state.username}
  27.             onChange={this.handleChange}
  28.           />
  29.         </form>
  30.       )
  31.     }
  32.   }
  33.  
  34. export default App;