Skip to content

Instantly share code, notes, and snippets.

@rcdexta
Created August 12, 2018 08:34
Show Gist options
  • Save rcdexta/cda15cf538f899d59efacd52f3a08f41 to your computer and use it in GitHub Desktop.
Save rcdexta/cda15cf538f899d59efacd52f3a08f41 to your computer and use it in GitHub Desktop.
BitcoinTicker
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