Created
          August 12, 2018 08:34 
        
      - 
      
- 
        Save rcdexta/cda15cf538f899d59efacd52f3a08f41 to your computer and use it in GitHub Desktop. 
    BitcoinTicker
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import React, { Component } from "react"; | |
| import Pollable from "@bit/rcdexta.hoc.components.pollable"; | |
| class BitcoinTicker extends Component { | |
| state = { value: null, lastUpdated: null }; | |
| componentDidMount() { | |
| this.props.onInterval(this.refresh); | |
| } | |
| refresh = () => { | |
| fetch("https://blockchain.info/es/ticker?cors=true") | |
| .then(res => res.json()) | |
| .then(res => | |
| this.setState({ value: res["USD"].last, lastUpdated: new Date() }) | |
| ); | |
| }; | |
| render() { | |
| return ( | |
| <div className="App"> | |
| <h1>Bitcoin USD value</h1> | |
| {this.state.value ? ( | |
| <div> | |
| <h2 className="timer">$ {this.state.value}</h2> | |
| <p>Updated {this.state.lastUpdated.toLocaleString()}</p> | |
| </div> | |
| ) : ( | |
| <span>fetching...</span> | |
| )} | |
| </div> | |
| ); | |
| } | |
| } | |
| export default Pollable(5)(BitcoinTicker); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment