Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import React from 'react';
  2. import {API_BASE_URL} from '../config';
  3.  
  4. export default class Coins extends React.Component {
  5. constructor(props) {
  6. super(props);
  7.  
  8. this.state = {
  9. lists: [],
  10. error: null,
  11. };
  12. }
  13.  
  14. componentDidMount() {
  15. this.loadCoins();
  16. }
  17.  
  18. loadCoins() {
  19. this.setState({
  20. error: null,
  21. loading: true
  22. });
  23. return fetch(`${API_BASE_URL}?limit=10&tsym=USD`)
  24. .then(res => {
  25. if(!res.ok) {
  26. return Promise.reject(res.statusText);
  27. }
  28. return res.json();
  29. })
  30. .then(coins =>
  31. this.setState({
  32. lists: coins.data,
  33. loading: false
  34. })
  35. )
  36. .catch(err => {
  37. this.setState({
  38. error: 'Could not load coins',
  39. loading: false
  40. })
  41. });
  42. }
  43.  
  44. render() {
  45. const coins = this.state.lists.map((coin, index) => (
  46. <li>{coin}</li>
  47. )
  48. return (<div></div>);
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement