Advertisement
joygabriel21

Display Remote Data

Jan 20th, 2020
104
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. import axios from "axios";
  3.  
  4. class FetchData extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. people: []
  9. };
  10. }
  11. componentDidMount() {
  12. axios
  13. .get("https://swapi.co/api/people")
  14. .then(response => this.setState({ people: response.data }));
  15. }
  16. render() {
  17. return (
  18. <div>
  19. <h1>Fetching data...</h1>
  20. <ul>{this.state.people.map(p => <li>{p.name}</li>)}</ul>
  21. </div>
  22. );
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement