Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- class ErrorrHandler extends Component {
- constructor(props) {
- super(props);
- this.state = { hasError: false };
- }
- componentDidCatch(error, info) {
- this.setState({ hasError: true });
- this.logError(error, info);
- }
- logError = (error, info) => {
- //Submit the error to some kind of logging service if available
- }
- render() {
- if (!this.state.hasError) {
- return this.props.children;
- }
- return (
- <span>
- <h2>An error has occured</h2>
- </span>
- );
- }
- }
- export default ErrorrHandler;
Add Comment
Please, Sign In to add comment