Advertisement
Qpel

g-2

Nov 13th, 2019
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React,{Component} from 'react';
  2. import ReactDOM from 'react-dom';
  3. import ListItem from './ListItem';
  4. class NameForm extends React.Component {
  5.   constructor(props) {
  6.     super(props);
  7.     this.state = {value: ''};
  8.     this.tekstas = "1";
  9.     this.handleChange = this.handleChange.bind(this);
  10.     this.handleSubmit = this.handleSubmit.bind(this);
  11.   }
  12.  
  13.   handleChange(event) {
  14.     this.setState({value: event.target.value});
  15.   }
  16.  
  17.   handleSubmit(event) {
  18.     this.tekstas = this.state.value;
  19.     //alert('A name was submitted: ' + this.state.value);
  20.     event.preventDefault();
  21.   }
  22.  
  23.   render() {
  24.     return (
  25.       <form onSubmit={this.handleSubmit}>
  26.         <label>
  27.           Name:
  28.           <input type="text" value={this.state.value} onChange={this.handleChange} />
  29.         </label><br></br>
  30.         <label>{this.tekstas}</label><br></br>
  31.         <input type="submit" value="Submit" />
  32.       </form>
  33.      
  34.     );
  35.   }
  36. }
  37.  
  38. ReactDOM.render(
  39.   <NameForm />,
  40.   document.getElementById('app')
  41. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement