I'm building a cryptocoin app with React and a JSON API for the latest data. I'm using fetch to load the JSON API and I use setInterval to rerender the app every 10 seconds.
Is there a way to compare the previous data with the new data?
For example, if a value is 3456 and the new value is 3458 I want to compare the old data with the new data and use an arrow up icon or so or give the value a green color. if the new data is 3454 a red color. I can do this with CSS of course. The thing I can't is to compare the difference between the old data and the new data.
my code so far:
GetCryptoData() {
let dataURL = this.props.coinUrl;
fetch(dataURL)
.then(res => res.json())
.then(res => {
this.setState({
item: res
})
})
componentDidMount(nextState) {
this.GetCryptoData();
setInterval(this.GetCryptoData.bind(this), 10000);
};
}