Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. class Form extends React.Component {
  2. constructor(props) {
  3. super(props);
  4.  
  5. this.state = {
  6. contact: {}
  7. };
  8. }
  9.  
  10. handleChange = e => {
  11. const target = e.target;
  12. const name = target.name;
  13. const value = target.value;
  14.  
  15. this.setState({
  16. [name]: value
  17. });
  18. }
  19.  
  20. render() {
  21. return (
  22. <form addContact={() => this.props.addContact(this.state.contact)}>
  23. <input value={this.state.name} type="text" name="name" onChange={this.handleChange} />
  24. <input value={this.state.tel} type="text" name="tel" onChange={this.handleChange} />
  25. <button className="submit">OK</button>
  26. </form>
  27. );
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement