Guest User

Untitled

a guest
Nov 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. class Component extends React.Component {
  4. constructor() {
  5. super();
  6. this.state = {
  7. data: [],
  8. };
  9. }
  10.  
  11. handleRequest = () => {
  12. fetch('/api')
  13. .then(res => res.json)
  14. .then(data => {
  15. this.setState({
  16. data
  17. });
  18. });
  19. }
  20. render() {
  21. console.log(this.state.data);
  22. return (
  23. <div>
  24. <button onClick={this.handleRequest}>
  25. Get Data
  26. </button>
  27. </div>
  28. );
  29. }
  30. }
  31.  
  32. export default Component;
Add Comment
Please, Sign In to add comment