Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import React, { Component } from "react";
  2.  
  3. class App extends Component {
  4. state = { messages: [], input: "" };
  5. onInput = e => {
  6. this.setState({ input: e.target.value });
  7. };
  8. onSubmit = e => {
  9. e.preventDefault();
  10. //the real submit action code here
  11. this.setState({ input: "" });
  12. };
  13. render() {
  14. const { messages, input } = this.state;
  15. return (
  16. <div>
  17. <hr />
  18. <input type="text" value={input} onChange={this.onInput} />
  19. <button onClick={this.onSubmit}>Submit</button>
  20. </div>
  21. );
  22. }
  23. }
  24.  
  25. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement