Last active
May 1, 2018 18:45
-
-
Save shsunmoonlee/ae03eab257a10350b92b83ea6b7a3d95 to your computer and use it in GitHub Desktop.
1. Getting Data https://medium.com/@seunghunsunmoonlee/crypto-currency-realtime-market-analysis-data-visualization-react-app-tutorial-4abcc857bdbe
This file contains 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
fetch = (params = {}) => { | |
this.setState({ loading: true }); | |
// Optionally the request above could also be done as | |
// console.log("fetch, limit", this.state.numberOfTopCoins, ) | |
axios.get('https://api.coinmarketcap.com/v1/ticker/', { | |
params: { | |
convert: 'EUR', | |
start: 0, | |
limit: this.state.numberOfTopCoins, | |
} | |
}) | |
.then((response) => { | |
const pagination = { ...this.state.pagination }; | |
// Read total count from server | |
// pagination.total = data.totalCount; | |
// pagination.total = 200; | |
this.props.setCoins(response.data) | |
this.setState({ | |
loading: false, | |
defaultData: response.data, | |
data: response.data, | |
pagination, | |
}); | |
}) | |
.catch(function (error) { | |
console.log(error); | |
}); | |
} | |
setCoins = (value) => { | |
if(value === "0") { | |
this.setState((prevState, props) => { | |
return {numberOfTopCoins: 0} | |
}); | |
this.fetch() | |
} | |
else { | |
this.setState((prevState, props) => { | |
this.props.setCoins(prevState.defaultData.slice(0, Number(value))) | |
return { data: prevState.defaultData.slice(0, Number(value)) } | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment