Last active
January 3, 2019 16:03
-
-
Save avremel/23c07962b79bac7aff5d4b3950d0172c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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