Skip to content

Instantly share code, notes, and snippets.

@avremel
Last active January 3, 2019 16:03
Show Gist options
  • Save avremel/23c07962b79bac7aff5d4b3950d0172c to your computer and use it in GitHub Desktop.
Save avremel/23c07962b79bac7aff5d4b3950d0172c to your computer and use it in GitHub Desktop.
import React from 'react'
class App extends Component {
state = {error: false}
componentDidMount() {
fetch(url)
.then(() => {
// do something
})
.catch(error => {
this.setState({error: true), () => Router.push(url)}
})
}
componentWillUnmount() {
// Unsubscribe here
if (this.state.error)
this.props.showAlert("fetch failed")
}
render () {
return (
<div>My App</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment