1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-26 19:49:26 +01:00

properly cancel axios requests

This commit is contained in:
Matthias Kretschmann 2019-06-07 13:51:33 +02:00
parent a900be9992
commit e7a871a080
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -116,6 +116,15 @@ class Numbers extends PureComponent {
}
url = 'https://oceanprotocol-github.now.sh'
signal = axios.CancelToken.source()
componentDidMount() {
this.fetchNumbers()
}
componentWillUnmount() {
this.signal.cancel()
}
fetchNumbers = async () => {
try {
@ -147,14 +156,14 @@ class Numbers extends PureComponent {
this.setState({ stars })
}
} catch (error) {
console.log(error) // eslint-disable-line no-console
if (axios.isCancel(error)) {
return null
} else {
console.log(error.message) // eslint-disable-line no-console
}
}
}
componentDidMount() {
this.fetchNumbers()
}
render() {
const { url } = this.props
const { forks, stars } = this.state