Skip to content

Instantly share code, notes, and snippets.

@vivek12345
Last active October 18, 2017 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivek12345/a83a85d8054fe4dedde8572df39eb16b to your computer and use it in GitHub Desktop.
Save vivek12345/a83a85d8054fe4dedde8572df39eb16b to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { Card, CardMedia, CardTitle, CardText } from 'react-toolbox/lib/card';
const style = {
width: '350px',
marginLeft: '20px',
marginTop: '20px',
display: 'inline-block'
};
class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = {
hasError: false
};
}
componentDidCatch(error, info) {
this.setState({
hasError: true
});
}
render() {
if(this.state.hasError) {
return (
<Card style={style}>
<CardMedia
aspectRatio="wide"
image="https://cdn.dribbble.com/users/1078347/screenshots/2799566/oops.png"
/>
<CardTitle
title="Sorry Something went wrong!!!"
subtitle="Error catched by error boundary of react 16"
/>
</Card>
);
}
return this.props.children;
}
}
export default ErrorBoundary;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment