Guest User

Untitled

a guest
Nov 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. componentDidMount() {
  2. fetch("http://localhost:8001/testing", {
  3. method: 'GET',
  4. headers: {
  5. 'Access-Control-Allow-Origin':'*',
  6. 'Access-Control-Allow-Methods':"GET, POST, PUT, DELETE,OPTIONS",
  7. 'Content-Type': '"application/json'
  8. }
  9. }).then(response => {
  10. response.json()
  11. .then(data => {
  12. console.log(data);
  13. let legoParts = data.map((legoPart) => {
  14.  
  15. return (
  16. <div key ={legoPart.id}>
  17. {legoPart.name}
  18. </div>
  19.  
  20. )
  21. })
  22.  
  23. this.setState({legoParts: legoParts})
  24. }
  25. );
  26.  
  27. })
  28. .catch(function(err) {
  29. console.log("i failed");
  30. });
  31. }
  32.  
  33. (2) [{…}, {…}]
  34. 0:{id: 1, piece: "tree", type: "garden"}
  35. 1: {id:2 piece:"hat" type: "clothes"}
  36. __proto__:Object
  37. length:2
  38. __proto__:Array(0)
Add Comment
Please, Sign In to add comment